PHP查询返回true但if语句仍在运行

PHP查询返回true但if语句仍在运行,php,mysql,mysql-real-escape-string,Php,Mysql,Mysql Real Escape String,我在发送查询时遇到了问题,这让我有点疯狂,以下是我要说的: $query = "INSERT INTO combined(v_products_model, v_products_image, v_products_description_1, v_products_name_1, v_products_quantity, v_tax_class_title, v_status, EOREOR) " . "VALUES ('$fileName', '$fileName'

我在发送查询时遇到了问题,这让我有点疯狂,以下是我要说的:

 $query = "INSERT INTO combined(v_products_model, v_products_image, v_products_description_1, v_products_name_1, v_products_quantity, v_tax_class_title, v_status, EOREOR) " .
            "VALUES ('$fileName', '$fileName', '$description', '$description', '10', '--none--', 'Active', 'EOREOR')";
    mysql_real_escape_string($fileName);
    mysql_real_escape_string($description);
    $queryResult = mysql_query($query, $connect);
//  die(var_dump($queryResult));

if (!$queryResult) {
    die("Error with query: line 40 <br>
                 Query: $query <br>
                 Error: " . mysql_error());
}

从生成的查询中:

'ALICE IN WONDERLAND we're a sk PUR TS S'
                       ^--- unescaped quote
由于您在生成查询字符串之后正在执行mysql\u real\u escape\u string,因此您没有将文本转义到查询中,因此您的查询失败。PHP将不会神奇地回到过去并重新整理您的$query=。。。行以反映转义调用的值

这并不能解释为什么没有显示错误消息。我所能想到的是,您已经有多个连接打开到MySQL,并且正在$connect连接上执行查询,该连接不是默认连接,例如,上次创建的连接,因此MySQL\u错误返回的是其他没有错误的连接的错误结果


请尝试mysql\u error$connect并查看是否收到任何错误消息。

这部分代码将导致查询因引号而失败

'ALICE IN WONDERLAND we're a sk PUR TS S', 'ALICE IN WONDERLAND we're a sk PUR TS S'
在插入这些值之前,可以使用函数addslashes来转义这些值。 e、 g

请记住,在使用addslashes的值上使用stripslashes删除引号转义

其次,您必须放置这些线

mysql_real_escape_string($fileName);
mysql_real_escape_string($description);

在生成查询之前。

在生成查询字符串变量$query之前,对变量调用mysql\u real\u escape\u字符串。替换发生在变量设置的那一刻,而不是像准备好的语句那样在执行的时候。这是一个文盲的答案。使用addslashes有什么意义?使用斜杠有什么意义?
addslashes(ALICE IN WONDERLAND we're a sk PUR TS S);
mysql_real_escape_string($fileName);
mysql_real_escape_string($description);