Page 1 of 1

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

Posted: Mon Jul 12, 2010 12:06 am
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...

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

Posted: Mon Jul 12, 2010 12:12 am
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.

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

Posted: Mon Jul 12, 2010 12:19 pm
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.