matthewchristianson Posted June 29, 2007 Share Posted June 29, 2007 I get the following error message when I run the script: Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\New Folder (2)\process.php on line 24 I am trying to write the session variables to a table called schools in a table called school_users, this all works when I simply put words in 'here' in the MySQL command part of my script. So this shows its all OK, (the POST values also work), but I think the trouble is when I use this: $_SESSION['school_name'] in the MySQL command part, that, I think is why I get the error. Help to tell me how to put these in SQL commands or renaming them to $variables or something would be greatly appreciated. My script is below: <?php session_start(); // This connects to the existing session ?> <html> <head> <title>process</title> </head> <body> <?php session_register ("school_name"); // Create a session variable called name session_register ("postcode"); // Create a session variable called job session_register ("teacher_name"); // Create a session variable called name session_register ("email"); // Create a session variable called job session_register ("password"); // Create a session variable called name session_register ("num_logins"); // Create a session variable called name $_SESSION['school_name'] = $_POST['postcode']; $_SESSION['postcode'] = $_POST['postcode']; $_SESSION['techer_name'] = $_POST['teacher_name']; $_SESSION['email'] = $_POST['email']; $_SESSION['num_logins'] = $_POST['num_logins']; mysql_connect("localhost", "root", "******") or die(mysql_error()); mysql_select_db("school_users") or die(mysql_error()); mysql_query("INSERT INTO schools VALUES ( '$_SESSION['school_name']', '$_SESSION['postcode']', '$_SESSION['techer_name']', '$_SESSION['email']', '$_SESSION['num_logins']' )"); ?> </body> </html> Thanks for any help. P.S I am failry new to PHP so the solution is probably very simple. MC Link to comment https://forums.phpfreaks.com/topic/57780-trouble-inserting-session-variables-into-a-database/ Share on other sites More sharing options...
dvd871 Posted June 29, 2007 Share Posted June 29, 2007 It's just like the other guys told you in your duplicated post. Your query has single quotes in it that is causing things to fail. Change: mysql_query("INSERT INTO schools VALUES ( '$_SESSION['school_name']', '$_SESSION['postcode']', '$_SESSION['teacher_name']', '$_SESSION['email']', '$_SESSION['num_logins']' )"); To: mysql_query("INSERT INTO schools VALUES ( '$_SESSION[school_name]', '$_SESSION[postcode]', '$_SESSION[teacher_name]', '$_SESSION', '$_SESSION[num_logins]' )"); Link to comment https://forums.phpfreaks.com/topic/57780-trouble-inserting-session-variables-into-a-database/#findComment-286200 Share on other sites More sharing options...
per1os Posted June 29, 2007 Share Posted June 29, 2007 Just an FYI, double posting is not cool... http://www.phpfreaks.com/forums/index.php/topic,147422.0.html Especially within minutes of each other... Link to comment https://forums.phpfreaks.com/topic/57780-trouble-inserting-session-variables-into-a-database/#findComment-286202 Share on other sites More sharing options...
ToonMariner Posted June 29, 2007 Share Posted June 29, 2007 why the hell would you need a session var storing in the database? Link to comment https://forums.phpfreaks.com/topic/57780-trouble-inserting-session-variables-into-a-database/#findComment-286213 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.