gpt4 book ai didi

php - #1064(42000) INSERT INTO 查询中的 MySQL 错误 PHP MySQL

转载 作者:行者123 更新时间:2023-11-29 12:05:11 25 4
gpt4 key购买 nike

我遇到了一些人遇到的同样的错误。但我的问题仍然没有解决。在我的所有模块的大学项目中,我都遇到了相同的错误。

当我在 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');

我遇到了同样的错误。您能帮我解决这个问题吗?我以各种方式检查了查询,但错误仍然存​​在。如果不解决这个问题,我就无法继续前进!感谢您的帮助!

最佳答案

表格标题上不需要撇号。

        $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')";

关于php - #1064(42000) INSERT INTO 查询中的 MySQL 错误 PHP MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31616999/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com