Jump to content
Larry Ullman's Book Forums

Login Script 12.12 And Session Data Problem.


Recommended Posts

The script in 12.12 uses a session to record the id number of a user listed in the users table.

The script identifies data from two columns or fields in the user table.

An integer in the field user_id is assigned to $_SESSION['user_id'].

But the value of  $_SESSION['user_id'] created in this script, is a string, not an integer!

I planned to use the value of this integer to query the table, but I can not use this string.

 

Clearly I am new to PHP/MYSQL.

If anyone can help me determine what I am doing wrong or how to extract the number (not a string) using the script of chapter12, it would be greatly appreciated.

 

Wes Smith

wesmith4@gmail.com

 

Link to comment
Share on other sites

Keep in mind most things in PHP and MySQL acts as a String even though the value is of the integer type. Try typecasting or parsing the value to an integer before anything else.

 

Try something along the lines of...

 

$row = mysqli_fetch_array($result, $dbc);

$_SESSION['id'] = (int) $row['user_id'];

  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...