开发者

MySQL error about updating table [duplicate]

开发者 https://www.devze.com 2023-03-17 17:35 出处:网络
This question already has answers here: How can I write SQL for a table that shares the same name as a protected keyword in MySql? [duplicate]
This question already has answers here: How can I write SQL for a table that shares the same name as a protected keyword in MySql? [duplicate] 开发者_高级运维 (3 answers) Closed 9 years ago.

What I want is to update my database table by selecting the row by index number and updating the answer field on that row.

This is my form's select; it puts the index id to the option value. Also there is a textarea with the name "answer".

<select name="indexno" style="width:150px">
<option selected="selected">&nbsp;</option>
<?php 
require('dbconnect.php');

$query = mysql_query("SELECT * FROM mytable WHERE answer = '' ");

while($result = mysql_fetch_array($query))
  {
  echo "<option " . "value='" . $result['index'] . "'>";
  echo $result['index'];
  echo "</option>";
  }

?>
</select>

This is the PHP code:

$indexno = $_POST['indexno'];
$answer = $_POST['answer'];
$date = gmdate("Y-m-d\TH:i:s\Z");
$query = "UPDATE mytable 
             SET answerfield = '$answer',
                 date = '$date' 
           WHERE index = '$indexno'";

$link = mysql_query($query);

However, it is not working; the error message is:

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 'index = '2'' at line 1


Try

WHERE `index` = '$indexno'";
0

精彩评论

暂无评论...
验证码 换一张
取 消