我有一个表C8
,其中包含gquestions
,id
,answer
列。我正在尝试使用此HTML表单和PHP查询更新表中的字符串:
HTML
date
PHP
<form action="/reply" method="post">
<textarea name="answer"></textarea><br>
<input type="submit" value="Reply">
</form>
好的,在表单中我输入textarea 测试并点击回复并在页面中获得此结果:
$p_answer = $_POST["answer"];
$time = time();
mysql_query("UPDATE gquestions SET answer='$p_answer' AND date='$time' WHERE id='1'");
echo "UPDATE gquestions SET answer='$p_answer' AND date='$time' WHERE id='1'";
但在表格中,我在UPDATE gquestions SET answer='Test' AND date='1490982467' id='1'
列中获得 0 而不是测试。为什么我在专栏中得到0?
答案 0 :(得分:1)
列类型不同,可能int将其更改为varchar或answer for answer列。
您的查询错误
"UPDATE gquestions SET answer='$p_answer' AND date='$time' WHERE id='1'"
应该不应该和
"UPDATE gquestions SET answer='$p_answer',date='$time' WHERE id='1'"
答案 1 :(得分:0)
更改
UPDATE gquestions SET answer='$p_answer' AND date='$time' WHERE id='1'
要
UPDATE gquestions SET answer='$p_answer', date='$time' WHERE id='1'
答案 2 :(得分:0)
更新您的代码
UPDATE gquestions SET answer='Test' AND date='1490982467' id='1'
到
UPDATE gquestions SET answer='Test' , date='1490982467' id='1'
这是常见的格式
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;