Jump to content

[SOLVED] Storing session in MYSQL


Ne.OnZ

Recommended Posts

Hello, I have a simple question. I have 2 pages, one looks like this:

 

for($i = 0; $i<10; $i++) {
	$temp = rand(0, 35);
                $code = "{$code}{$temp}";
         }
         $_SESSION['key'] = $code;

That works out perfectly. On the other page I have this:

$key = $_SESSION['key'];
"INSERT INTO users(username, password, email, rank, avatar, code) VALUES('$username', '$password', '$email', '1', 
'http://divnx.net/images/no_avatar.gif', '$key')";

 

This is where the problem lies. It doesn't insert the $key into the database. I tried to set code in mysql to VARCHAR, CHAR, INT, and BIGINT. Still No luck. Any ideas to what may be wrong?

 

Thank You!

Link to comment
Share on other sites

Yes if I echo $key, the string comes up. The session is set on the 1st page. I'll give you more code:

 

1st Page:

for($i = 0; $i<10; $i++) {
	$temp = rand(0, 35);
                $code = "{$code}{$temp}";
         }
         $_SESSION['key'] = $code;

 

After you hit submit on the form: 2nd Page

$key = $_SESSION['key'];
function register($username, $password, $email, &$res)
{
    $que = "INSERT INTO users(username, password, email, rank, avatar, code) VALUES('$username', '$password', '$email', '1', 
'http://divnx.net/images/no_avatar.gif', '$key')";
    $res = mysql_query($que) OR die(mysql_error());
}
if($username && $password && $password2 && $email && $checkbox && $security == $_SESSION['key'] && !$set)
{
    register($username, $password, $email, $res);
}

 

Hope this helps a bit more. Thank You!

Link to comment
Share on other sites

well, $key comes from $_SESSION['key'] and $_SESSION['key'] comes from $code so echo $_SESSION['key'] and $code and post what happens

 

edit:

 

well, $key is on your 2nd page, so... are you sure you have session_start(); on the top of your page? And on the page where you initially set it? Because I see no reason (based on your code provided) why $code shouldn't contain info, which means your session variable is the problem.

Link to comment
Share on other sites

Your function is already using parameters for $username, $password, $email, $res. Add $key as a parameter for consistency. A month from now or a year from now when you need to do anything with this code, you will find that consistency will make your life easier.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

×
×
  • 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.