php - mysql_real_escape_string 不工作

标签 php mysql mysql-real-escape-string

我的 mysql_real_escape_string 被忽略了。这让我很难受,因为我觉得我错过了一些微小的东西。

$htmlText 变量来自 TinyMCE 编辑器,其中文本呈现为 HTML,即带有标签等。

<?php 
    /*--------GLOBAL PROCEDURES--------*/
    session_start();
    require "../scr/config-data.php.inc";
    mysql_connect($host,$username,$password) or die 
    ("Could Not Connect".mysql_error());
    mysql_select_db($db) or die ("Could Not Connect".mysql_error());

    /*-----SEVERAL SELECT/INSERT QUERIES, ALL WORKING FINE-----*/

    /*--------SPECIFIC PROCEDURES-------*/      
    if($_POST['submit']){
        //Check that POS has been chosen
        $htmlText = mysql_real_escape_string($_POST['cust']);
        if($htmlText != ""){
            mysql_query("INSERT INTO table VALUES(NULL, '$htmlText' )") or die(mysql_error());
        }else{
            $feedback = "Please Enter some text into the editor";
        }
    }

    /*--------CLOSING PROCEDURES-------*/
    mysql_close();

?>

奇怪的是,它改编自一个有效的脚本,只是更改了变量名。我在 MySQL 语法中遇到错误。它也没有转义文本中的 HTML,所以我收到了这个错误:

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 'order VALUES(NULL, '

sfgafgafs

')' at line 1

最佳答案

从您给出的错误消息看来,您正在使用 order 作为表名,恰好是 MySQL reserved word .

尝试用反引号括起来。

关于php - mysql_real_escape_string 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4759869/

相关文章:

用于复杂查询的 MySQL 子查询未知列

php - 如何验证 laravel 中插入的图像数组并需要根据验证插入枚举值?

php - 从 scandir 中排除隐藏文件

sql - 在 SQL 中,没有 Count(*) 或 Sum()、Max()、avg() 等的 Group By 是什么意思,它有哪些用途?

php - mysqli 查询问题。 mysqli_real_escape_string 错误

PHP 将 implode() 与 mysql_real_escape_string() 结合使用时出现问题

php - PHP的addslashes和mysql(i)_escape_string有什么区别?

java - 如何提取和比较 HttpPost 响应字符串?

javascript - 更新数据库 OnClick() <a>

php - 尝试将我的数据库导出为 XML 文件并出现 "Extra content at end of document"错误