#1064(42000) MySQL INSERT INTO 查询出错 PHP MySQL
#1064(42000) MySQL Error in INSERT INTO query PHP MySQL
我遇到了一些人遇到的同样的错误。但是我的问题还是没有解决。在我所有模块的大学项目中,我遇到了同样的错误。
当我 运行 在 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 - 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 ''id','user_id','post','date_added') VALUES (NULL,'3','erye yeyeyeyetyery ery ery '' at line 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');
我遇到了同样的错误。你能帮我解决 this.I 尽我所能检查查询的问题吗?错误仍然存在。我无法继续解决这个问题!感谢您的帮助!
您的 table headers 不需要撇号。
$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')";
鉴于 id
是 primary-key
和 auto-increment
,您可以排除它。您还可以使用本机 Mysql 函数 now()
for date_added
$Query = "INSERT INTO `posts` (user_id, post, date_added) VALUES ('$enteruser','$forum',now())";
试试这个...
$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')";`
我遇到了一些人遇到的同样的错误。但是我的问题还是没有解决。在我所有模块的大学项目中,我遇到了同样的错误。
当我 运行 在 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 - 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 ''id','user_id','post','date_added') VALUES (NULL,'3','erye yeyeyeyetyery ery ery '' at line 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');
我遇到了同样的错误。你能帮我解决 this.I 尽我所能检查查询的问题吗?错误仍然存在。我无法继续解决这个问题!感谢您的帮助!
您的 table headers 不需要撇号。
$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')";
鉴于 id
是 primary-key
和 auto-increment
,您可以排除它。您还可以使用本机 Mysql 函数 now()
for date_added
$Query = "INSERT INTO `posts` (user_id, post, date_added) VALUES ('$enteruser','$forum',now())";
试试这个...
$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')";`