tags:

views:

50

answers:

3

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

+5  A: 

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'
Eric
thanks alot. it works now
Zeeshan Rang
A: 

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;
Gumbo
A: 

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.

MacAnthony