945,065 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 111613
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Sep 3rd, 2009
0

Problem: expects parameter 1 to be resource

Expand Post »
Hi all,

I've been hitting the same problem over and over in my development. Sometimes when i do a MySQL query I keep getting the error
Warning: mysql_fetch_row() expects parameter 1 to be resource.

I don't understand why. What does this error mean, am I doing something wrong? I've googled it but I just get pages with the same error...

I'm using php 5.3, it's definitely not my mysql statement. I'm lost >.<

I even simplify my query code and still the same problem. The general code look something like this:
PHP Syntax (Toggle Plain Text)
  1. require "dbconn.php";
  2. $id=$_POST['id'];
  3. $checkquery = "SELECT * FROM table WHERE id = '$id'";
  4. $checkresults = mysql_query($checkquery);
  5. $row = mysql_fetch_row ($checkresults);

It crashes on the last line
Similar Threads
Reputation Points: 11
Solved Threads: 1
Junior Poster in Training
Avasulthiris is offline Offline
54 posts
since Jun 2009
Sep 3rd, 2009
0

Re: Problem: expects parameter 1 to be resource

Take a look at the FAQ that is stickied, follow those instructions and then if it still doesn't work repost your code along with the new errors
Sponsor
Reputation Points: 526
Solved Threads: 268
Code Monkey
ShawnCplus is offline Offline
1,564 posts
since Apr 2005
Sep 3rd, 2009
0

Re: Problem: expects parameter 1 to be resource

Still cant find anything. What do you mean by stickied?

The code is literally as simple as what I have above in my original thread. I'm just trying to understand the error.

It's been popping up everywhere. Even with the most simple code. It's unhappy with the mysql_fetch_row command.

Sometimes it works if i copy the code into a new file. I thought I might be using reserved words in mysql, but i'm definitely not. The database also has nothing weird in. It's just being weird.

And I have to finish this system by tomorrow night >.<
*is stressing*

What does that error mean? How is $checkresults not a resource?
Reputation Points: 11
Solved Threads: 1
Junior Poster in Training
Avasulthiris is offline Offline
54 posts
since Jun 2009
Sep 3rd, 2009
0

Re: Problem: expects parameter 1 to be resource

php Syntax (Toggle Plain Text)
  1. require "dbconn.php";
  2. $id=$_POST['id'];
  3. $checkquery = "SELECT * FROM table WHERE id = '$id'";
  4. $checkresults = mysql_query($checkquery);
  5. var_dump($checkresults);
  6. die();
  7. $row = mysql_fetch_row ($checkresults);

Do that and post the output
Sponsor
Reputation Points: 526
Solved Threads: 268
Code Monkey
ShawnCplus is offline Offline
1,564 posts
since Apr 2005
Sep 4th, 2009
0

Re: Problem: expects parameter 1 to be resource

php Syntax (Toggle Plain Text)
  1.  
  2. require "dbconn.php";
  3. $id=$_POST['id'];
  4. $checkquery = "SELECT * FROM table WHERE id = '$id'";
  5. $checkresults = mysql_query($checkquery);
  6. $row = mysql_fetch_row ($checkresults);require "dbconn.php";
  7. $id=$_POST['id'];
  8. $checkquery = "SELECT * FROM table WHERE id = '$id'";
  9. $checkresults = mysql_query($checkquery);
  10. if($checkresults && mysql_num_rows($checkresults)>0)
  11. {
  12. $row = mysql_fetch_row ($checkresults);
  13. }
  14. else
  15. {
  16. if(!$checkresults)
  17. echo "Error in query: ".mysql_error();
  18. else
  19. echo "No record Found";
  20. }
Reputation Points: 10
Solved Threads: 5
Junior Poster in Training
dasatti is offline Offline
57 posts
since Dec 2008
Sep 4th, 2009
0

Re: Problem: expects parameter 1 to be resource

I changed my code entirely throughout the night and now that specific problem is gone.

I do still occasionally get the same error, I just dont have an example of it right now. When i printf the error it comes out blank. It's been boggling me for a while.

I will post an example as soon as I run into it again
Reputation Points: 11
Solved Threads: 1
Junior Poster in Training
Avasulthiris is offline Offline
54 posts
since Jun 2009
Sep 4th, 2009
0

Re: Problem: expects parameter 1 to be resource

Here we go, its happening in 4 different places now:

This is the error:
PHP Syntax (Toggle Plain Text)
  1. Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in C:\wamp\www\EIRMSv2\pages\upload_rename_ac.php on line 135

This is they code in that section(lines 130-135):
PHP Syntax (Toggle Plain Text)
  1. require "dbconn.php";
  2.  
  3. $checkquery = "SELECT * FROM flowchart WHERE id = '$id'";
  4. $checkresults = mysql_query($checkquery);
  5.  
  6. $row = mysql_fetch_row ($checkresults);

My dbconn file definitely works. My values are posted correctly...

If i do a var_dump it returns bool(false). I dont know what that means?
Reputation Points: 11
Solved Threads: 1
Junior Poster in Training
Avasulthiris is offline Offline
54 posts
since Jun 2009
Sep 4th, 2009
0

Re: Problem: expects parameter 1 to be resource

You must use if($checkresults) check out side the statement $row = mysql_fetch_row ($checkresults);
php Syntax (Toggle Plain Text)
  1. $checkquery = "SELECT * FROM flowchart WHERE id = '$id'";
  2. $checkresults = mysql_query($checkquery);
  3. if($checkresults)
  4. {
  5. $row = mysql_fetch_row ($checkresults);
  6. }

The reason is when it encounters some invalid $id, the mysql_query() function does not return valid result set. You can use mysql_error() to find out the reason why returned resultset is not valid
Last edited by dasatti; Sep 4th, 2009 at 7:57 am.
Reputation Points: 10
Solved Threads: 5
Junior Poster in Training
dasatti is offline Offline
57 posts
since Dec 2008
Sep 4th, 2009
0

Re: Problem: expects parameter 1 to be resource

One of the reasons that invalid result set is returned could be you are comparing a string value with an integer type field in database.

Make sure that if the id field in flowchart table is int then use this statement $checkquery = "SELECT * FROM flowchart WHERE id = $id"; instead of $checkquery = "SELECT * FROM flowchart WHERE id = '$id'";
Last edited by dasatti; Sep 4th, 2009 at 8:06 am.
Reputation Points: 10
Solved Threads: 5
Junior Poster in Training
dasatti is offline Offline
57 posts
since Dec 2008
Sep 4th, 2009
0

Re: Problem: expects parameter 1 to be resource

Another module of the project im working on is mysqli instead of mysql. Could it be that that is causing the problems? That module uses its own dbconn file though so i dunno why its having this issue
Reputation Points: 11
Solved Threads: 1
Junior Poster in Training
Avasulthiris is offline Offline
54 posts
since Jun 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: php script adding record twice - Not sure why
Next Thread in PHP Forum Timeline: Need help with search engine





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC