无法找到PHP语法错误

时间:2012-09-09 14:43:22

标签: php sql-server syntax

我有一个之前有效的PHP MSSQL查询,因为我更改了一个看似与查询无关的元素,它已经开始抛出错误。

以下是查询:

<?php 
if (isset($_POST['paper'])) {

$PageHTML = $_POST['ckeditor'];
$PageID = $_GET['id'];

$myServer = "**.***.***.**";
$myUser = "username";
$myPass = "password";
$myDB = "database";

$dbhandle = mssql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer"); 
mssql_select_db($myDB) or die;

$dbTABLE = "Table_Name";
$query_sql = sprintf("UPDATE %s SET PageHTML = ('%s') WHERE PageID = '%d'",
$dbTABLE,
$PageHTML,
$PageID); 

if ($result = mssql_query($query_sql, $dbhandle)) {
header('Location: Manage.php');
}
}
?>

错误已经开始投掷如下:

Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near 're'.   (severity 15) in (file path) on line 59

Warning: mssql_query() [function.mssql-query]: message: Unclosed quotation mark after  the character string '</p> </div> </td> </tr> </tbody> </table>') WHERE PageID = '2''.   (severity 15) in (file path) on line 59
第59行是这一行:

if ($result = mssql_query($query_sql, $dbhandle)) {

我已经检查过,并且在其他方​​面使用了类似的语法。任何人都可以看到它的错误吗?

1 个答案:

答案 0 :(得分:0)

您正在尝试将HTML代码添加到数据库中,并且引号和特殊符号存在问题。是的,你可以说你正在做sprintf(),但该功能不解决sql语法问题。试试addslashes()或者清理php函数。