2012-09-06 33 views
0

我在運行此代碼時遇到此錯誤。Mysqli的解析錯誤Prepare Statement

Parse error: syntax error, unexpected 'users_kudos_to_posts' (T_STRING) 

該代碼。

if ($number > 0) { 

$arr=explode(",",`$upvoted); 
//If I comment out everything below I still get the error. But if I comment out 
//the above code, then the error goes away. 
if (in_array($primary_id, $arr)) {   
array_push($arr, $primary_id); 
$new_string = implode(",", $arr); 
//the line below is where the parse error is pointing too. 
    if ($stmt2 = $mysqli->prepare("UPDATE `users_kudos_to_posts` SET `upvoted` = ? 
     WHERE `user_id` = ?")) { 
     $stmt2->bind_param('si', $new_string, $session_user_id); 
     $stmt2->execute(); 
     $stmt2->close(); 
    } 
} 
    } 

什麼是瘋狂的是,我有相同的代碼頁面除了在列的變化相同的SQL語句等多重準備的語句和他們工作還沒有這樣做不行。

另外,我在phpmyAdmin中運行了sql語句,它的工作原理。

+0

聽起來像一個PHP語法錯誤。也許你做了更多的事情。如果你評論這一行呢?錯誤消失/改變了嗎? – Mike

+0

我評論了我在問題中顯示的代碼,並且錯誤仍然彈出。我以前從來沒有見過。 – jason328

+0

這意味着錯誤進一步增加。更有可能你在某個地方多了一個或缺少引號。我建議你得到一個語法高亮的文本編輯器,因爲這可能會使錯誤更加明顯。 – Mike

回答

1

問題是這一行:

$arr=explode(",",`$upvoted); 

您有不屬於有額外的反引號。它應該是:

$arr=explode(",",$upvoted); 
0

由於StackOverflow上的語法高亮亮點(嘿嘿),你有一個額外的反引號在explode聲明前的`$upvoted

$arr=explode(",",`$upvoted);