-3

Possible Duplicate:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result

I am fetching data from MySQL data base in PHP but it gives error like following:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/i/h/u/ihus235/html/cs/emrapp/surveyList.php on line 97 []

Below is the query which I am using to select data:

 $query = mysql_query("SELECT * form survey_Profile where user_Id='".$user_id."' ");
2
  • You have an error in your sql syntax. Verify if survey_Profile table and user_Id field exists Commented Sep 20, 2012 at 6:04
  • after $query type in echo mysql_error() Commented Sep 20, 2012 at 6:07

3 Answers 3

5

change

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

to

$query = mysql_query("SELECT * from survey_Profile where user_Id='".$user_id."' ");
Sign up to request clarification or add additional context in comments.

5 Comments

why downvote the problem was in form, i changed it to from.
I saw it now.. sorry.. I switched my vote :)
yes downvote to "matei mihai"
@YogeshSuthar: In the future, it's a good idea to make note of what you change, to avoid situations like this where it's extremely hard to spot. Good catch. :-)
@drrcknlsn thanks...for advice...
2

The cause of tthat error can be that mysql returns False. You can add an:

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

To see what string is send to mysql, eventualy test it directly in phpmyadmin. Also, add this code to see the error from mysql:

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

Comments

0

You are getting this error because user_id value doesn't exist into your table.

So before executing your resource into mysql_fetch_assoc(), check whether you got matching rows or not.

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

And also you have sql syntax error, in your query replace "form" to "from"

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.