Jump to content

Query does not match session!


bytesize
 Share

Recommended Posts

I need help making $_SESSION['code'] match variable $code when executed. They're both accessing rand() but with different results.

<?php
function create_user($params)
{
db_connect_posts();

$code = rand(11111111,99999999);

$_SESSION['code'] = $code;

$query = sprintf("INSERT INTO users 
SET
	users.screen_name = '%s',
	users.user_email = '%s',
	users.user_pwd = '%s',
	users.image = '%s',
	created_at = NOW(),
	users.code = $code,
	users.active = '0'"
	, mysql_real_escape_string($params['screen_name']),
		mysql_real_escape_string($params['user_email']),
		md5($params['user_pwd']),
		mysql_real_escape_string($params['image'])
	);

$result = mysql_query($query);

if(!$result)
{
return false;
}
else
{
return true;
}
}
?>

Link to comment
Share on other sites

'$code = rand(11111111,99999999)' is inserted into the database with 'users.code = $code' and '$_SESSION['code']' is using '$code = rand(11111111,99999999)' as well.

 

The INSERT 'users.code = $code' and $_SESSION['code'] return different results. They must match.

Link to comment
Share on other sites

I'm confused as well.

 

In the script above you are generating a random number and 1) creating a new record in the database and setting one of the fields to that value and then 2) setting a session variable to the same value.

 

You are saying the two values do not match. Exactly "WHERE" do they not match? You are obviously not comparing the two variables in the above script, so I must assume you are seeing the problem on another page. I will further assume you are storing the code as a session variable so you can grab the user's data from the database on subsequent page loads.

 

So, are your queries returning no records on subsequent pages (i.e. no record is returned)? I don't see you starting the session in the above code. Don't know if that is the problem or if you jest left that off for brevity.

 

Basically, what you are asking makes no sense within the context of the code you have provided.

Link to comment
Share on other sites

The session is started elsewhere. The session is being used on register.php page that inserts into the database. When the query is echoed from user.php, which is the supplied code above, and the form is echoed from register.php the results are different. I can supply more code if necessary.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.