Php 即使新行在数据库中,SQL插入也会失败?

Php 即使新行在数据库中,SQL插入也会失败?,php,sql,mysqli,sql-insert,Php,Sql,Mysqli,Sql Insert,我正在PHP类中使用mysqli 我要执行以下查询: INSERT INTO notifications (userid, content, uniq, link) VALUES (48, "[2014-07-30] Nomid has edited the post \"Somepost\"", "934512e1e9314d9c602a02a26114a625", "http://website/somepost") 失败,显示错误: 您的查询等出现错误,请在“[2014-07-30]No

我正在PHP类中使用mysqli

我要执行以下查询:

INSERT INTO notifications (userid, content, uniq, link) VALUES (48, "[2014-07-30] Nomid has edited the post \"Somepost\"", "934512e1e9314d9c602a02a26114a625", "http://website/somepost")
失败,显示错误:

您的查询等出现错误,请在“[2014-07-30]Nomid已编辑帖子\Somepost\,934512e1e9314d9”附近使用

但是如果我查看数据库,就会看到新行

使用mysqli\u real\u escape\u字符串对参数进行转义:

$msg = $this->escape($msg);
$uniqid = $this->escape($uniqid);

$sql = "INSERT INTO notifications (userid, content, uniq, link) VALUES ($userid, \"$msg\", \"$uniqid\", \"$link\")";
// die($sql);
$this->query($sql);
我试图用$mysqli->受影响的行和$mysqli_查询的结果

字段类型为

INT 11表示用户ID, 文本内容, uniq和Unix的TINYTEXT TINYTEXT用于链接

所有文本字段都有排序规则utf8\U general\U ci

我没有创建表

奇怪的是,如果我查看数据库,查询成功执行

为什么会发生这种情况?

您应该

$userid = $this->escape($userid);
$msg = $this->escape($msg);
$uniqid = $this->escape($uniqid);
$link = $this->escape($link);

$sql = "INSERT INTO notifications (userid, content, uniq, link) VALUES ('$userid', '$msg', '$uniqid', '$link')";

如果已经使用$this->escape$msg进行了转义,我想您不需要对双引号使用escape character\。否则请尝试使用$msg=mysqli\u real\u escape\u字符串$msg;如果您在通知中插入$sql=userid、content、uniq、link值$userid、$msg、$uniqid、$link;,是否仍然失败;?删除了Bakslashes sql字符串的反斜杠是因为该值是使用双引号插入的:value with\double quotes\查询在数据库中执行得很好,我可以读取该行,但它失败了:|$this->escape是mysqli_real_escape_字符串的别名,我在解释中写的删除反斜杠它将删除错误消息…反斜杠是PHP字符串转义,而不是SQL字符串。我也尝试过,但仍然得到相同的错误,但新行在DB中仍然可读,这是奇怪的事情我使用双引号得到的相同错误。但是,即使有错误,查询实际上也成功地在数据库中插入了。是的,仍然会得到相同的错误消息,因此问题不在于引号。。。但是,这一行实际上还是插入到了数据库中。我认为您的转义函数工作不正常$this->escape是mysqli\u real\u escape\u字符串的别名