MySQL关于更新表的错误
我想要的是通过按索引号选择行并更新该行上的答案字段来更新我的数据库表。
这是我的表格的选择;它将索引 id 放入选项值中。还有一个名为“answer”的文本区域。
<select name="indexno" style="width:150px">
<option selected="selected"> </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);
但是,它不起作用;错误消息是:
您的 SQL 语法有错误;检查手册 与您的 MySQL 服务器版本相对应,以便使用正确的语法 第 1 行“index = '2”附近
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"> </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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
Try