0

I am have some problem in updating my qotwVote1a table's Vote1a field through PHP. Could you please have a look at the code, and tell me what am i doing wrong in here.

$result = mysql_query("SELECT * FROM qotwVote1a WHERE QuestionId='".$questionId."' AND MemberId='".$id."'");

    while($row = mysql_fetch_array($result))
    {
        $originalVote=$row['Vote1a'];
        $newVote=$originalVote + $vote;
        //echo ($newVote);
    }

$sql = <<<END
UPDATE qotwVote1a
SET Vote1a = '$newVote',
WHERE QuestionId = '$questionId' AND MemberId = '$id'
END;

mysql_query($sql);
if (mysql_error()) {
  die("Error executing query '$sql': " . mysql_error());
}

Using this code I got an error:

"Error executing query 'UPDATE qotwVote1a SET Vote1a = '2', WHERE QuestionId = '57' AND MemberId = 'zee'': You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE QuestionId = '57' AND MemberId = 'zee'' at line 3"

Regards Zeeshan

3 Answers 3

5

You have a comma after $newVote. Remove it, and you'll be peachy-keen.

Also, you don't need to wrap numbers in quotation marks, and don't do it if your column is an integer or float type. Doing so just causes those to get converted to numbers, anyway, so it's not a big deal.

UPDATE qotwVote1a
SET Vote1a = '$newVote'
WHERE QuestionId = '$questionId' AND MemberId = '$id'
Sign up to request clarification or add additional context in comments.

Comments

0

There’s a comma in you MySQL query after the SET clause that’s misplaced. So try this:

$sql = <<<END
UPDATE qotwVote1a
SET Vote1a = '$newVote'
WHERE QuestionId = '$questionId' AND MemberId = '$id'
END;

Comments

0

It's looks like you are missing some code as the query supplied is not the query giving the error. The problem in the query is an extra comma after the "Vote1a = '2'" statement though.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.