MySQL有关更新表的错误 [英] MySQL error about updating table

查看:97
本文介绍了MySQL有关更新表的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的是通过按索引号选择行并更新该行的答案字段来更新数据库表.

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

这是我表单的选择;它将索引ID设置为选项值.还有一个名为答案"的文本区域.

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>

这是PHP代码:

$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:

您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本以使用正确的语法 在第1行的'index ='2'附近

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

推荐答案

尝试

WHERE `index` = '$indexno'";

这篇关于MySQL有关更新表的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆