2012-05-09 19 views
0

非常に具体的な質問がありますが、問題は見つかりません。私はいくつかのテキストを更新してみてください、と私はエラーを取得:段落を更新しようとした後にMYSQLエラーが発生する

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 '= Easter in Corfu is considered to be the most magnificent celebration in Gree' at line 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; 

すべての変数の作品は、私がエコーしようとしたが、何も問題ありません。テキストに挿入写真(またはゼロ)が1つしかない場合、それは機能します。私には複数のものがあるが、このエラーが出る。なぜか手がかりがないのですか?

答えて

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

+0

をチェック! :) ありがとうございました!私はこのページが大好き!あなたが手紙を逃しただけのmysql_real_escape_string – user1384668

0

$stringをエスケープしてからクエリに入れる必要があります。

$stringには、'という文字が含まれているため、クエリが間違っています。

2

".$string."の前後に引用符はありません。

さらに、私はmysql_real_string_escape()への呼び出しを見ることができません。何故なの?

1
mysql_query("UPDATE paragraph SET text_content=".$string." WHERE id='$id'") 
mysql_query("UPDATE paragraph SET text_content='".$string."' WHERE id='".$id"') 

それが働いているあなたの要求

関連する問題