2009-09-28 92 views
0

如何在PHP中將爆炸字與mysql varchar進行比較?
此代碼產生我想要什麼,但它也給這個錯誤PHP - 在PHP中將爆炸字與mysql varchar進行比較

veranderenwachtwoordjij
致命錯誤:調用一個成員函數FETCH_ASSOC()一個非對象......

$word = "Also, to be safe, change your password regularly... you don't have to be obsessive about it: every three hours or so should be enough. And because erring on the side of caution is always a good idea, fake your own suicide and change your identity at least once a year."; 

$pieces = explode(" ", $word); 

$x = 0; 
while($x < word_count($word)) { // word count function returns int (51) 
    $aPiece = $pieces[$x]; // change $pieces[$x] to 'you' and then it works 
    $result = $conn->query("SELECT * FROM dict WHERE english='$aPiece'"); 

    $z = 0; 
    while($z < $num_result) // $num_result returns amount of rows in database 
    { 
    $row = $result->fetch_assoc(); //error line is here 
    echo stripslashes($row['dutch']); 
    $z++; 
    } 

    $x++; 
} 
+0

自從我做任何PHP以來,這已經很長時間了。他們是否棄用'for'循環? – Johnsyweb 2010-09-06 09:41:45

回答

0

我認爲

$row = $result2->fetch_assoc();

應該

$row = $result->fetch_assoc();

因爲您似乎沒有任何地方有$結果。

+1

oops ..這是一個錯字 應該是$ row = $ result-> fetch_assoc(); – Azam 2009-09-28 19:01:15

1

我想問題來自您的測試語句中的don't:您忘記使用mysql_real_escape_string等函數來避開引號。

例如:

在$ result2-
$aPiece = mysql_real_escape_string($pieces[$x]); 
$result = $conn->query("SELECT * FROM dict WHERE english='$aPiece'"); 
0

$ RESULT2> FETCH_ASSOC();不正確的變量,它應該是

$result->fetch_assoc(); 

由您必須刪除,以便找到的話在數據庫中標點符號的方式(我覺得)你的第一線之一應(前的爆炸)與此類似:

$words = strtr($words, ',.:!',''); 
+0

它已經在word_count函數中:) – Azam 2009-09-28 19:46:52