未知的列‘阿布’在‘字段列表’,所以这里是一个小注释框,我正在http://abu.cpvp.net/cupcakes.php WHen我把我的名字和评论它不会工作,但是,如果我把名字字段和评论字段它工作?这是我的脚本
$name=$_POST['name'];
$comment=$_POST['comment'];
$submit=$_POST['post'];
if($_POST['name'] && $_POST['comment'] && $submit)
{
$insert=mysql_query("INSERT INTO `comment (`name`,`comment`)
VALUES ($name,$comment) " ) or die(mysql_error());
}
else
{
echo "please fill out all fields";
}发布于 2013-05-02 09:23:14
如果列的数据类型是字符串,那么值应该用单引号括起来,因为它们是字符串文字。
INSERT INTO comment (name,comment) VALUES ('$name','$comment')顺便说一句,如果变量的值来自外部,则查询容易受到SQL Injection的攻击。请看下面的文章,了解如何预防它。通过使用PreparedStatements,您可以避免使用单引号将值引起来。
发布于 2013-05-02 09:23:32
您需要将字符串放在引号中:
$insert=mysql_query("INSERT INTO comment
(name,comment)
VALUES ($name,$comment) " ) 应该是
$insert=mysql_query("INSERT INTO comment
(name,comment)
VALUES ('$name','$comment') " ) Please, don't use mysql_* functions in new code。它们不再由and are officially deprecated维护。看到red box了吗?相反,学习,并使用PDO或MySQLi - this article将帮助您决定使用哪种方法。如果你选择PDO,here is a good tutorial。
您也对 敞开心怀
发布于 2013-05-02 09:34:43
INSERT INTO comment (name,comment) VALUES ('$name','$comment')会解决你的问题..但是其他开发人员可能已经注意到了,但没有指出..您尚未关闭SQL查询的反引号:
INSERT INTO `comment 应该是:
INSERT INTO `comment`在列/表/架构名称中使用反引号没有任何错误。实际上,建议使用它们,以将遇到SQL保留字的风险降至最低。如果它们是正确打开/关闭的
https://stackoverflow.com/questions/16328927
复制相似问题