Trying to insert $_COOKIE into MySQL, result is always '0'

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
adamjoiner
Forum Newbie
Posts: 8
Joined: Sun Jul 11, 2010 11:57 pm

Trying to insert $_COOKIE into MySQL, result is always '0'

Post by adamjoiner »

I am trying to attach a referrer ID to each new account that is created. I have this ID saving to a cookie and, at the end of the following MySQL insert, I call the $_COOKIE superglobal to insert the contents into the 'refid' column:

Code: Select all

	if ( $result > 0) {		
		$query = "INSERT #__comprofiler  ( `id` , `user_id` , `firstname` , `middlename` , `lastname` , `hits` , `message_last_sent` , `message_number_sent` , `avatar` , `avatarapproved` , `approved` , `confirmed` , `lastupdatedate` , `registeripaddr` , `cbactivation` , `banned` , `banneddate` , `unbanneddate` , `bannedby` , `unbannedby` , `bannedreason` , `acceptedterms` , `refid` ) VALUES(".  $user->get('id') . ',' .  $user->get('id') .", NULL , NULL , NULL , '0', '0000-00-00 00:00:00', '0', NULL , '1', '1', '1', '0000-00-00 00:00:00', '', '', '0', NULL , NULL , NULL , NULL , NULL , '0' , '" . $_COOKIE['refidC'] . "' )";
However every time I run this script all it inserts is a 0 in the 'refid' column. I've tried everything! If I replace "$_COOKIE['refidC']" with any made up number like "514" it stores it into that column just fine, so I know that this code is working.

HELP?! I haven't been this stumped in a long time...
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Re: Trying to insert $_COOKIE into MySQL, result is always '

Post by liljester »

try this:

Code: Select all

print_r($_COOKIE);
is $_COOKIE populated with what you think it should be? im going to guess that your problem is not the sql.
adamjoiner
Forum Newbie
Posts: 8
Joined: Sun Jul 11, 2010 11:57 pm

Re: Trying to insert $_COOKIE into MySQL, result is always '

Post by adamjoiner »

I think you're right. It MUST not be populated with the ID number because I know that code works fine. I cant test it though because the .php file that contains this code does not print to anything. Its just a reference file containing the 'Post to DB' function. Could that maybe be part of my problem? I obviously didn't write the original code myself.
Post Reply