0

我有一个非常具体的问题,我找不到问题。我尝试更新一些文本,但出现错误:

您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的“= 科孚岛的复活节被认为是格力最盛大的庆祝活动”附近使用正确的语法

我的代码:

$arr = explode("|", $id, 2);
$id = $arr[0];
$part = $arr[1];                                                // in which part of a splited paragraph currently we are
$row = mysql_fetch_array(mysql_query("SELECT * FROM paragraph WHERE id=$id")) or die(mysql_error());    
$search = 'insertphotos';                                       // the string to search for     
$string = $row['text_content'];                                 // the string to search
$repetition = substr_count($string, $search);                   // how many insertphotos exist in paragraph
if ($repetition > $part){   
    if ($part > 1)
        $offset = $part - 1;                                    // how many times to search for word insertphotos
    else
        $offset = $part;
    $start = strposOffset($search, $string, $offset) + 13;      // find position of '$offset' occurance of search string
    $offset++;
    $end = strposOffset($search, $string, $offset) - $start - 1;
    $string = substr_replace($string, $value, $start, $end);
}else if ($repetition == $part){
    $offset = $part;                                        // how many times to search for word insertphotos
    $start = strposOffset($search, $string, $offset) + 13;      // find position of '$offset' occurance of search string
    $string = substr_replace($string, $value, $start, strlen($string)); 
}else
    $string = "<p>".$value."</p>";
//$value = "<p>".$value."</p>";
mysql_query("UPDATE paragraph SET text_content=".$string." WHERE id='$id'") or die(mysql_error());  
//mysql_query("INSERT INTO paragraph (header, text_content, menu_id, sequence) VALUES('<h2>Bella Vista Hotel h2 - Please Change Me</h2>', $string, '15', '2')") or die(mysql_error());
mysql_close($link);     
//echo "INSERT PHOTOS REPEATS " .$repetition ." ID =".$id ." PART = ".$part ." WE SEARCH, START AT " .$start ." FINISH AT " .$end ." SEARCH FOR OFFSET = " .$offset ." FINAL STRING " .$string;
echo $string;

每个变量都有效,我尝试回显,没有任何问题。如果文本中只有一张插入照片(或零张),它可以工作。虽然我有不止一个,但我得到了这个错误。我不知道为什么?

4

4 回答 4

3

您的文本字符串没有被引用。

mysql_query("UPDATE paragraph SET text_content='".mysql_real_escape_string($string)."' WHERE id='$id'") or die(mysql_error());

您还应该转义您的输入: http: //php.net/manual/en/function.mysql-real-escape-string.php

于 2012-05-09T13:16:46.870 回答
2

插入的 . 周围没有引号".$string."

此外,我看不到对 的调用mysql_real_string_escape()。为什么不?

于 2012-05-09T13:16:37.577 回答
1
mysql_query("UPDATE paragraph SET text_content=".$string." WHERE id='$id'")
mysql_query("UPDATE paragraph SET text_content='".$string."' WHERE id='".$id"')

检查您的请求

于 2012-05-09T13:29:12.730 回答
0

$string在将其放入查询之前,您需要对其进行转义。

$string包含一个'使您的查询错误的字符。

于 2012-05-09T13:16:13.923 回答