2012-09-20 31 views
-3

可能重複:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result獲取數據

我在PHP MySQL數據庫中獲取數據,但它給錯誤,如下列:

警告:mysql_fetch_assoc():提供的參數不是第97行的/home/content/i/h/u/ihus235/html/cs/emrapp/surveyList.php中的有效MySQL結果資源。 []

下面是我使用的選擇數據的查詢:

$query = mysql_query("SELECT * form survey_Profile where user_Id='".$user_id."' "); 
+0

您在您的sql語法中有錯誤。驗證'survey_rofile'表和'user_Id'字段是否存在 –

+0

''echo'mysql_error()'中的$ query'類型' –

回答

5

變化

$query = mysql_query("SELECT * form survey_Profile where user_Id='".$user_id."' "); 

$query = mysql_query("SELECT * from survey_Profile where user_Id='".$user_id."' "); 
+1

我在這裏沒有看到任何更改 –

+0

感謝它爲我工作 –

+1

爲什麼downvote問題是'形式',我將它改爲'from'。 –

0

因爲user_id的值不您收到此錯誤存在你的表中。

所以在執行你的資源到mysql_fetch_assoc()之前,檢查你是否有匹配的行。

if(mysql_num_rows($query) > 0) { 
//user mysql_fetch_assoc now 
} 

,你也有SQL語法錯誤,在您的查詢替換「形式」到「從」

2

tthat錯誤的原因可能是,MySQL的返回False。 您可以添加:

echo "SELECT * form survey_Profile where user_Id='".$user_id."' "; 

要查看字符串發送到MySQL,eventualy直接在phpMyAdmin測試。 此外,添加此代碼以查看來自mysql的錯誤:

if (mysql_errno()) { 
    echo "<br />". mysql_errno(). " : ". mysql_error(). "<br />"; 
}