关于php:你的SQL语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获得在 \’\’ 附近使用的正确语法

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 ''

使用表单,我试图将数据插入到我的数据库中。最初的 SQL 查询有值的变量,但它不起作用。在尝试了一些事情并使用 mysqli_error 之后,我无法找到问题所在。然后我用字符串替换了所有变量,但我的数据没有插入。

我已尝试将以下代码嵌套在 PHP 的其他位中,但不起作用。我在另一个页面上试过了,没有用。所以我剥离了所有东西,只留下了 mysql_connect 链接和 mysqli_query,它仍然不会插入。

这是我得到的 MySQL 错误:

error - 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 '' at line 2

我的代码如下:

1
2
3
4
5
6
7
8
9
10
11
$link = mysqli_connect("host","username","password","database") or die("cannot connect"));
$try = mysqli_query($link,"INSERT INTO troubleshooting_files (`title`, `asset`, `image`, `category`, `file`)
VALUES ('title', 'asset', 'image', 'cat', 'file'"
);
//$try = mysqli_query($link,"INSERT INTO troubleshooting_users (`name`)
//VALUES ('title'");
if($try === false){
    echo 'error - ';
    echo mysqli_error($link);
}   else{
        echo 'all good';
    }

我尝试只输入一个字段,我尝试在字段名称中不带 `s,我尝试了不同的表名称,但它不起作用。 phpMyAdmin 可以很好地将数据插入表中。
我在服务器上的另一个目录中也有 PHP 代码,可以将数据很好地插入到该数据库中,尽管该代码目前仍使用已弃用的 mysql_query。我还有代码可以将此服务器上的行很好地插入到不同的数据库中。如果 PMA 可以正常插入数据,我假设数据库必须没问题,并且在我的脚本中的其他地方,其他 mysqli_query 工作正常,因为我可以正常获取对象和更新表。

相关讨论

  • 只是尝试将表名 Troubleshooting_files 放在`s
  • @lord_linus 不幸的是,这仍然会产生相同的错误
  • 嘿,如果您得到答案,请接受答案并为答案投票
  • 必须等待 2 分钟,仅供参考

缺少 VALUES 的右括号...

1
2
$try = mysqli_query($link,"INSERT INTO troubleshooting_files (`title`, `asset`, `image`, `category`, `file`)
VALUES ('title', 'asset', 'image', 'cat', 'file')"
);

相关讨论

  • 我真的不敢相信。但是谢谢,这就是问题所在!希望 mysqli_error 可以让查找变得稍微容易一些!当我首先看到你的答案时,我会接受它

你缺少括号:

1
2
VALUES ('title', 'asset', 'image', 'cat', 'file')");
                                                ^^--------here missing bracket

相关讨论

  • 更改测试不会有任何区别,因为 mysql_query 失败将 === false 无论如何。

你错过了 values()

的括号

1
2
$try = mysqli_query($link,"INSERT INTO troubleshooting_files (`title`, `asset`, `image`, `category`, `file`)
VALUES ('title', 'asset', 'image', 'cat', 'file')"
);

以上是关于php:你的SQL语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获得在 \’\’ 附近使用的正确语法的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>