简体   繁体   English

MySQL + PHP:谁能告诉我这段代码有什么问题?

[英]MySQL+PHP: Can anyone tell me what is wrong with this code?

I am having problems running this script, but i keep on getting the same error message. 我在运行此脚本时遇到问题,但我不断收到相同的错误消息。 Could someone point out where I am going wrong? 有人可以指出我要去哪里了吗? Thanks. 谢谢。

Error message: You have an error in your SQL syntax; 错误消息:您的SQL语法有错误。 check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 检查与您的MySQL服务器版本相对应的手册,以在第1行的''附近使用正确的语法

 $datenow = date("Y-m-d") . " " . date("H:i:s");
 $conn = mysql_connect('localhost', 'admin', 'root') or die(mysql_error());
mysql_select_db('main') or die(mysql_error());

 $queryh =  "INSERT INTO user_comments (posted_by, posted_to, comment, date_posted) ".
        " VALUES ('{$postman}', '{$id}', '{$comment}', '{$datenow}' ";

 $result = mysql_query($queryh) or die(mysql_error());

 echo "posted";

You are missing the close-parenthesis on your values list. 您在值列表中缺少右括号。

" VALUES ('{$postman}', '{$id}', '{$comment}', '{$datenow}' ";
                                                           ^
                                             Close-parenthesis goes here

As a tip, 提示

$datenow = date("Y-m-d") . " " . date("H:i:s");

can be shortened to be: 可以简化为:

$datenow = date("Y-m-d H:i:s");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM