Hi,
I am working on a music website that sells cds.
When a person clicks on a cd they are taken to a page through a link http://....../detail_cd.php?cdid=3
The cds are all registered in the database with their unique cdids.
I am trying to write some code which will automatically record the cdid in a cdsbrowsed table in the database for the registered user when they click on the link above.
I first want to check they have not browsed the same cd before because i don't want to record it twice for that person in the cdsbrowsed table.
Here is the relevant part of my code:
if (session_is_registered("valid_user2")){
//Query the database to check not repeat cd browsed for that customer id
$query= "SELECT cdid FROM cdsbrowsed
WHERE customerid= '$valid_user2'
AND cdid=".$HTTP_GET_VARS['cdid'];
$result = mysql_query($query);
$cdid = mysql_result($result, 0, "cdid");
if(!$result)
{
echo 'Cannot run query.';
exit;
}
if ($result && (mysql_num_rows($result)>0)){
echo "No new cdid inserted into database";
}else
//insert new cdid to cdbrowsed for customerid registered
if (!$query("insert into cdsbrowsed values ('".$valid_user2."','".$cdid."')"));
echo "cdid added.";
}
When the user clicks on the link this message is displayed:
Warning: Supplied argument is not a valid MySQL result resource in /cs/u22h/cs3dbs1/nzw99d/cgi-bin/detail_cd.php on line 38
Cannot run query.
Can anyone see what i am doing wrong??????
Thanks, Nicola.