Supplied argument is not a valid MySQL result resource

Thread Solved

Join Date: Jun 2005
Posts: 1
Reputation: sri_sep29 is an unknown quantity at this point 
Solved Threads: 0
sri_sep29 sri_sep29 is offline Offline
Newbie Poster

Supplied argument is not a valid MySQL result resource

 
0
  #1
Jun 23rd, 2005
hi,

i write a code like this

$user_id = $hd_cookie['user_id'];
$user_password = $hd_cookie['auth'];


$sql = "SELECT * FROM hd_users WHERE user_id='$user_id' AND user_password='$user_password'";

$r_user = mysql_query($sql);
$num=mysql_num_rows($r_user); //line 24

it shows Warning
Warning: Supplied argument is not a valid MySQL result resource in c:\apache\htdocs\helpdeskfinal\includes\auth.php on line 24

when i print the sql statement and run the statement in MySql Window it gives the result.but from here it didn't give the result why?

i am using PHPTRIAD 2.1.1 version is this version supports mysql_num_rows????

please solve my problem

Thanks
Srinivas
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 763
Reputation: Phaelax is on a distinguished road 
Solved Threads: 38
Phaelax Phaelax is offline Offline
Master Poster

Re: Supplied argument is not a valid MySQL result resource

 
0
  #2
Jun 23rd, 2005
It might return an error if the result of the SELECT contained no rows, but I could be wrong. The code looks ok, I'm not sure what the problem could be.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 354
Reputation: Troy is an unknown quantity at this point 
Solved Threads: 5
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: Supplied argument is not a valid MySQL result resource

 
0
  #3
Jun 23rd, 2005
Debugging tip: You mention that you run the statement in MySql window, and it works, but did you actually copy & paste the statement as generated by your code? Right after you build the $sql variable, output it like so:
[php]
echo $sql;
exit();
[/php]
Then copy & paste that output in your MySql query windows and see if it works. You may find your problem.
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 1
Reputation: Jero is an unknown quantity at this point 
Solved Threads: 1
Jero Jero is offline Offline
Newbie Poster

Re: Supplied argument is not a valid MySQL result resource

 
0
  #4
Aug 26th, 2005
I had exactly the same problem and I knew for certain I did spell the cellnames and tablename right.

I've found the solution. Simply put all the cellnames and tablename between ``. That's all!

[php]
$sql = "SELECT * FROM `hd_users` WHERE `user_id`='$user_id' AND `user_password`='$user_password'";
[/php]

If this doesn't work, first get the user_id and user_password out of the ``, only hd_users. If that doesn't work either, I don't it, for me it worked

grtz, Jero
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 2
Reputation: manofgames is an unknown quantity at this point 
Solved Threads: 1
manofgames manofgames is offline Offline
Newbie Poster

Re: Supplied argument is not a valid MySQL result resource

 
0
  #5
Feb 28th, 2007
Thanks very much, I've just find this via google, and its got me out of a tight spot

Thanks again, and sorry to bring up an old topic
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1
Reputation: gregarious is an unknown quantity at this point 
Solved Threads: 1
gregarious gregarious is offline Offline
Newbie Poster

Re: Supplied argument is not a valid MySQL result resource

 
0
  #6
Aug 18th, 2007
Thanks, this thread helped me figure out a problem I was having too.

In my case, the problem was a missing semicolon at the end of the SQL statement. Was this also the problem for the original poster, I wonder?

In other words, this:

  1. ...snip... AND user_password='$user_password'";
  2.  

should have been this:

  1. ...snip... AND user_password='$user_password';";
  2.  
Last edited by gregarious; Aug 18th, 2007 at 5:20 am. Reason: clarify with code example
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1
Reputation: BrandonJoyce356 is an unknown quantity at this point 
Solved Threads: 1
BrandonJoyce356 BrandonJoyce356 is offline Offline
Newbie Poster

Re: Supplied argument is not a valid MySQL result resource

 
0
  #7
Feb 2nd, 2009
The gotcha for me was remembering to use the mysql_select_db() function. I use mysql_connect() and then mysql_select_db() before I do the mysql_query. Like this...

  1. $sql_conn = mysql_connect($hostName, $dbuser, $dbpass);
  2. mysql_select_db($databaseName, $sql_conn);
  3. $sql = "select * from tablename;";
  4. $rs = mysql_query($sql, $sql_conn);

That did the trick for me.

<URL SNIPPED>
Last edited by peter_budo; Feb 3rd, 2009 at 2:01 pm. Reason: Keep It On The Site - Do not manually post "fake" signatures in your posts. Instead, you may create a sitewide signature within the user control panel.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1
Reputation: sanjayagida is an unknown quantity at this point 
Solved Threads: 0
sanjayagida sanjayagida is offline Offline
Newbie Poster

Re: Supplied argument is not a valid MySQL result resource

 
0
  #8
Feb 9th, 2009
The error caused by mysql_select_db not connected to the database.
Most of the time because you don't have the privilege to the database or your database in MySQL has no user set for it yet.

Here is how to check:
From your cpanel, go to MySQL Databases.
Check your User for the database that you use if it empty.
If its empty, you need to add from Add User To Database below.
If its not empty, match them with the one you set in your mysql_connect()
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 27
Reputation: elamigosam is an unknown quantity at this point 
Solved Threads: 1
elamigosam elamigosam is offline Offline
Light Poster

Re: Supplied argument is not a valid MySQL result resource

 
0
  #9
Jun 16th, 2009
I dont know if this help you guys, but I fixed my error by removing a # simbol that was in the name of my table
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 1
Reputation: djmeltdown is an unknown quantity at this point 
Solved Threads: 0
djmeltdown djmeltdown is offline Offline
Newbie Poster

Re: Supplied argument is not a valid MySQL result resource

 
0
  #10
Jun 17th, 2009
This error is usually caused by the mysql_query statement querying the wrong connecting string, are you connecting to more than 1 database?

The easiest fix is to implicitly specify the connection string in the SQL Statement

mysql_query($sql,$con);
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC