bearzilla Posted December 21, 2006 Share Posted December 21, 2006 I've got a multi-page quiz, and am using $_SESSIONS for the first time so each user input gets tied to the same record. On the first question, I've got:$sql = "INSERT INTO quiz ( qone ) VALUES('$qone')"; this works, and gets the answer gets entered into the db.I'm messing up somewhere on the second question because it doesn't get entered into the qtwo column:$sql = "UPDATE myquiz ( qtwo ) VALUES('$qtwo') WHERE id = $_SESSION[id]";yet, when I do an echo $_SESSION["id"]; .... it prints correctly. Link to comment https://forums.phpfreaks.com/topic/31512-sessions-and-update-mysql/ Share on other sites More sharing options...
HuggieBear Posted December 21, 2006 Share Posted December 21, 2006 Is [code=php:0]$_SESSION['id'][/code] a number?Can we also see a bit more of the code?RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/31512-sessions-and-update-mysql/#findComment-145965 Share on other sites More sharing options...
bearzilla Posted December 21, 2006 Author Share Posted December 21, 2006 $_SESSION['id'] is how I stored the value of the auto-increment id column in the mysql table. a little more:session_start();if($_REQUEST['qtwo'] == "true") {$qtwo = "Incorrect";} if($_REQUEST['qtwo'] == "false") {$qtwo = "Correct";}$sql = "UPDATE myquiz ( qtwo )VALUES('$qtwo') WHERE id = $_SESSION[id]";mysql_query($sql); Link to comment https://forums.phpfreaks.com/topic/31512-sessions-and-update-mysql/#findComment-145976 Share on other sites More sharing options...
HuggieBear Posted December 21, 2006 Share Posted December 21, 2006 Your update syntax is incorrect, it should be in the following format...[code=php:0]UPDATE table_name SET column_name = 'value' WHERE column_name = 'condition'[/code] So your code should be...[code=php:0]UPDATE myquiz SET qtwo = '$qtwo' WHERE id = {$_SESSION['id']}[/code] RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/31512-sessions-and-update-mysql/#findComment-146016 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.