Ad:
 
  • MySQL Discussion Thread
  • Marked Solved
  • Views: 97209
  • MySQL RSS
Similar Threads
Jun 23rd, 2005
0

Supplied argument is not a valid MySQL result resource

Expand Post »
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sri_sep29 is offline Offline
1 posts
since Jun 2005
Jun 23rd, 2005
0

Re: Supplied argument is not a valid MySQL result resource

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.
Reputation Points: 92
Solved Threads: 44
Practically a Posting Shark
Phaelax is offline Offline
842 posts
since Mar 2004
Jun 23rd, 2005
0

Re: Supplied argument is not a valid MySQL result resource

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.
Reputation Points: 35
Solved Threads: 6
Posting Whiz
Troy is offline Offline
354 posts
since Jun 2005
Aug 26th, 2005
0

Re: Supplied argument is not a valid MySQL result resource

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
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Jero is offline Offline
1 posts
since Aug 2005
Feb 28th, 2007
0

Re: Supplied argument is not a valid MySQL result resource

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
Reputation Points: 10
Solved Threads: 1
Newbie Poster
manofgames is offline Offline
2 posts
since Feb 2007
Aug 18th, 2007
0

Re: Supplied argument is not a valid MySQL result resource

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:

MySQL Syntax (Toggle Plain Text)
  1. ...snip... AND user_password='$user_password'";
  2.  

should have been this:

MySQL Syntax (Toggle Plain Text)
  1. ...snip... AND user_password='$user_password';";
  2.  
Last edited by gregarious; Aug 18th, 2007 at 4:20 am. Reason: clarify with code example
Reputation Points: 10
Solved Threads: 1
Newbie Poster
gregarious is offline Offline
1 posts
since Aug 2007
Feb 2nd, 2009
0

Re: Supplied argument is not a valid MySQL result resource

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...

MySQL Syntax (Toggle Plain Text)
  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 1: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.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
BrandonJoyce356 is offline Offline
1 posts
since Feb 2009
Feb 9th, 2009
0

Re: Supplied argument is not a valid MySQL result resource

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()
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sanjayagida is offline Offline
1 posts
since Feb 2009
Jun 16th, 2009
0

Re: Supplied argument is not a valid MySQL result resource

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
Reputation Points: 10
Solved Threads: 2
Light Poster
elamigosam is offline Offline
31 posts
since Jun 2009
Jun 17th, 2009
0

Re: Supplied argument is not a valid MySQL result resource

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);
Reputation Points: 10
Solved Threads: 0
Newbie Poster
djmeltdown is offline Offline
1 posts
since Jun 2009
This thread is solved. Perhaps start a new thread instead?
This thread is more than three months old. Perhaps start a new thread instead?
Message:
Previous Thread in MySQL Forum Timeline: Update Stmt - Update same record multiple times
Next Thread in MySQL Forum Timeline: how to check table existince in a stored procedure using mysql





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


Follow us on Twitter


© 2010 DaniWeb® LLC