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
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);
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.