I’m trying to insert the session_id along with other values into a database table when the user signs up, however the session_id field always ends up blank in the database, which is very weird, because I’m starting the session correctly with session_start(), I’ve even used var_dump at the session_id and the string that I’m using to execute the query in order to see if the session id is in there, and it is. Another funny thing is that when I place any other string instead of the result generated from session_id() it is registered in the database, unless the string I’m trying to use is the result taken from the var_dump() on session_id(), which is very strange, because if I go to another browser and generate a different session id, copy and paste it there, it works, also if I use the same SQL statement directly into SQL command prompt or phpMyAdmin using the session_id() that I can’t insert with PHP, it works perfectly. I don’t know why but it’s not allowing me to insert the id of the current session via mysql_query. My code is the following:
$email = mysql_real_escape_string($_POST['signup_email']);
$password = md5(mysql_real_escape_string($_POST['signup_password']));
$origPassword = mysql_real_escape_string($_POST['signup_password']);
$first_name = mysql_real_escape_string($_POST['first_name']);
$last_name = mysql_real_escape_string($_POST['last_name']);
$mobile_phone = mysql_real_escape_string($_POST['mobile_phone']);
$sessionID = session_id();
$fullName = mysql_real_escape_string($first_name." ".$last_name);
var_dump($sessionID);
//Inserting user info
$q_user = "INSERT INTO
minders (
name,
phone,
ssid,
insert_datetime,
status,
email,
password,
is_minder,
login_allowed
)
VALUES
(
'{$fullName}',
'{$mobile_phone}',
'{$sessionID}',
now(),
'deactivated',
'{$email}',
'{$password}',
0,
1
)";
var_dump($q_user);
$r_user = mysql_query($q_user) or die(mysql_error());
I hope someone can help me with that. Thanks very much! Note: I know mysql_query is deprecated but isn’t feasible for me to change it.