我的 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/