Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get names of cookies and run them against database

Status
Not open for further replies.

sharapov

MIS
May 28, 2002
106
US
I set several cookies on the page. Now I need to get the name of each cookie I set and run it against my database if the name from the cookie matches the "ID" in my database I want to display this record. Can anybody help?

I tried to do the following, but it doesn't work:

<?

if (isset ($_COOKIE)) {
while (list ($cname, $cvalue) = each ($_COOKIE)) {

@ $db = mysql_pconnect(&quot;localhost&quot;, &quot;my_login&quot;, &quot;my_password&quot;);

if (!$db)
{
echo &quot;Error: Could not connect to database. Please try again later.&quot;;
exit;
}

mysql_select_db(&quot;catalog&quot;);

$query = &quot;select * from pricelist where item_number = '$cname'&quot;;
$result = mysql_query($query);

$num_results = mysql_num_rows($result);

for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);


$item_number = stripslashes($row[&quot;item_number&quot;]);
echo $item_number;

$description = stripslashes($row[&quot;description&quot;]);
echo $description;

.
.
.

}
}

}

?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top