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