Jump to content

sessions and UPDATE mysql


bearzilla

Recommended Posts

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

$_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);
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]

Regards
Huggie

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.