housemydog — 2014-04-23T06:23:47-04:00 — #1
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);
//Inserting user info
$q_user = "INSERT INTO
$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.
droopsnoot — 2014-04-23T08:40:03-04:00 — #2
Obvious question I know, but how much space have you allowed in the database column for the session ID? I don't know if it would truncate or just fail to write if it overflowed, maybe that's a config setting. I understand the length varies depending on config as well.
housemydog — 2014-04-23T09:19:50-04:00 — #3
The field is a VARCHAR of length 120, and think that is enough.
droopsnoot — 2014-04-24T08:34:21-04:00 — #4
Looking at some sample code around, do you need to call escape_string() on the sessionID? Other code seems to do that, but I cannot tell whether it needs to in the real world or whether it's just covering all bases.
And yes, maximum session ID seems to be 40 characters, so your column is probably big enough.
spacephoenix — 2014-04-24T14:24:21-04:00 — #5
Not changing away from mysql_* functions is not really an option, as soon as your host upgrades the server to a version where the mysql_* functions have been removed, your site will be well and truly broken. Have a read of this SitePoint article which explains about migrating over to PDO.
Double check that your using session_start() before this script is called
oddz — 2014-04-24T14:41:28-04:00 — #6
Well if the site is not owned or maintained by the op than it is the clients problem not the developers.
housemydog — 2014-04-25T06:22:26-04:00 — #7
I've already tried to call escape_string(), I don't think it is really needed, but I tried for safeness, but the problem remained.
housemydog — 2014-04-25T06:25:50-04:00 — #8
Thanks, I'll take a look at the article.
system — 2014-10-08T01:57:18-04:00 — #9
This topic is now closed. New replies are no longer allowed.