Forum Moderators: coopster

Message Too Old, No Replies

Using $_SESSION in a DB query?

I don't think the varibles are getting passed

         

freshrod

7:21 pm on May 7, 2006 (gmt 0)

10+ Year Member



I posted before related to this same script, but I think I asked the wrong question. After trying everything, I think I've figured out there wasn't anything wrong with my code (at least not that I or anyone else could find), but rather the variables I was trying to use weren't getting passed.

What I'm trying to do is set up a users DB that has two sets of information. The first is the basic stuff (i.e. name, email, adress, etc...), and the second is more personal information (i.e. tell us about your life, spouse, kids, job, etc...). The first set is filled out when they register. The second set is optional, but I want to check whether or not they have, and then let them know and provide a link to do so if they wish.

What I wanted to do was, instead of checking all the optional fields, just create a field that is set up like this:

'alumInfo enum ('0','1') NOT NULL default='0',

Once they filled out the optional and submited I would have upated the field to '1'.

The problem is that I can't seem to get the script:

$sql = mysql_query
("SELECT * FROM users WHERE username='$username' AND password='$password' AND alumInfo='0'");

$alumInfo_check = mysql_num_rows($sql); //should just return the users alumIfo.

echo '<p>username is: ',$row['username'],'<p>'; //nothing.
echo '<p>password is: ',$row['password'],'<p>'; //nothing.
echo '<p>alumInfo is: ',$row['alumInfo'],'<p>'; //nothing.

if($alumInfo_check > 0) { // it should since the default is '0' and I have checked in the MySQL command line client.
echo "Please let us know more about you by completing the Alumni Information form. <br /><a href=\"alumInfo.php\">Alumni Information Form</a>"; // So it should print this line.

} else {
echo "If you need to update or edit your Alumni Information follow this link.
<br /><a href=\"updateInfo.php\">Alumni Information Form</a><br />"; // Instead it prints this one.
}

to produce anything. No username, password...nothing.

These variables are defined as $_SESSION's on the previous page like so:

session_register('username');
$_SESSION['username'] = $username;
session_register('password');
$_SESSION['password'] = $password;

and I have session_start() at the top of this page.

The only thing I can think is that $username and $password aren't defined. If you agree, any ideas how I can fix that?

dreamcatcher

10:33 pm on May 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



freshrod,

Firstly, if you are assigning variables to the $_SESSION superglobal array, you don`t need to use session_register as well.

Your session variables are set correctly, but you are accessing them incorrectly. try changing:

SELECT * FROM users WHERE username='$username' AND password='$password' AND alumInfo='0

to:

SELECT * FROM users WHERE username='".$_SESSION['username']."' AND password='".$_SESSION['password']."' AND alumInfo='0

dc

freshrod

12:42 am on May 8, 2006 (gmt 0)

10+ Year Member



DREAMCATHER!

THANK YOU! THANK YOU! THANK YOU! THANK YOU! THANK YOU! THANK YOU! THANK YOU! THANK YOU! THANK YOU! THANK YOU!

You don't know how long I have been trying to figure that out! I've had that on a few different forums too. I knew there was a way, but I didn't know if I was asking the right question. Thank you sooooo much!

Now I can continue... until the next snag XD

dreamcatcher

7:03 am on May 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



LOL. You`re welcome. :)