我得到了一些人在这里得到的同样的错误。但我的问题仍未解决。在我的所有模块的大学项目中我得到了同样的错误。
当我在PHP中运行以下查询
时$username = $_SESSION['username'];
$query = "SELECT id FROM user WHERE username = '$username'";
$qpost = mysqli_query($connection,$query);
$post_user = mysqli_fetch_assoc($qpost);
$forum_size = strlen($forum);
$dt = time();
$datetime = strftime("%Y-%m-%d %H:%M:%S", $dt);
$enteruser = $post_user['id'];
$Query = "INSERT INTO posts('id','user_id','post','date_added') VALUES(NULL,'$enteruser','$forum','$datetime')";`
我收到以下错误,
#1064 - 您的SQL语法出错;查看与您的MySQL服务器版本相对应的手册,以便在'' id',' user_id',' post',&##附近使用正确的语法39; date_added')VALUES(NULL,' 3',' erye yeyeyeyetyery ery ery'在第1行
当我在mysql shell中运行它时,我得到了同样的错误。 当我在phpmyadmin中运行该查询时,如下所示,
INSERT INTO posts('id','user_id','post','date_added') VALUES (NULL,3,'erye yeyeyeyetyery ery ery ','2015-07-24 18:53:48');
我得到了同样的错误。你能帮我解决一下这个问题。我以各种方式检查了查询,我可以提出错误。我不能继续解决这个问题!谢谢你的帮助!
答案 0 :(得分:1)
您的表格标题上不需要撇号。
$username = $_SESSION['username'];
$query = "SELECT id FROM user WHERE username = '$username'";
$qpost = mysqli_query($connection,$query);
$post_user = mysqli_fetch_assoc($qpost);
$forum_size = strlen($forum);
$dt = time();
$datetime = strftime("%Y-%m-%d %H:%M:%S", $dt);
$enteruser = $post_user['id'];
$Query = "INSERT INTO `posts` (id, user_id, post, date_added) VALUES (NULL,'$enteruser','$forum','$datetime')";
答案 1 :(得分:0)
鉴于id
为primary-key
和auto-increment
,您可以将其排除。您还可以对now()
date_added
$Query = "INSERT INTO `posts` (user_id, post, date_added) VALUES ('$enteruser','$forum',now())";
答案 2 :(得分:0)
试试这个......
$username = $_SESSION['username'];
$query = "SELECT id FROM user WHERE username = '$username'";
$qpost = mysqli_query($connection,$query);
$post_user = mysqli_fetch_assoc($qpost);
$forum_size = strlen($forum);
$dt = time();
$datetime = strftime("%Y-%m-%d %H:%M:%S", $dt);
$enteruser = $post_user['id'];
$Query = "INSERT INTO posts ('user_id','post','date_added') VALUES('$enteruser','$forum','$datetime')";`