PHP Check Cookie Exists Not Working

Hi Guys,

I’m trying to check if a cookie exists or not and if it does then it will add a record to the database. How ever for some reason the record is not being added. If i remove the code to check if the cookie exists then the record is added which leave me to believe there is something wrong with the code when checking if the cookie exists or not. Below is the code:



//CHECK IF COOKIE EXISTS BEFORE ADDING LEAD TO DATABASE
if(isset($_cookie['lnm_click'])){; 
$query="INSERT INTO affleads VALUES ('','$p','$pname','$affid','$subid','$adid','$click','$leadip','$status','$referer','$affpayout','$netpayout','$datenow','$timenow')";
mysql_query($query) or dies(mysql_error()); 
mysql_close();
}else{ 
//do nothing
} 


I know the cookie exists as im using a Firefox addon for me to view my cookies. If someone can help that would be great. Thanks in advance.

Thanks

$_cookie != $_COOKIE .

You’ve got an extraneous semicolon at the end of the if line. dies is not a default function (die is)

Thank you, hate stupid little problems that take hours to find out and to find it something stupid.

Get into the habit of adding temp lines [fphp]var_dump/fphping your variables and you will catch this kind of thing.


var_dump($_cookie);

// and used most frequently:
//var_dump($_GET);
//var_dump($_POST);
//var_dump($_COOKIE);

Also you may want to get into the habbit of using PDO to do your SQL query, instead of mysql_* (mysql_query(), mysql_connect etc) as mysql_* as of PHP 5.4 it will be softly deprecated.