hi,

i write a code like this

$user_id = $hd_cookie;
$user_password = $hd_cookie;


$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

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.

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:

echo $sql;
exit();

Then copy & paste that output in your MySql query windows and see if it works. You may find your problem.

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!

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

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

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 :(

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:

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

should have been this:

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

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

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

That did the trick for me.

<URL SNIPPED>

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()

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

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);

$q1="SELECT categoryproduct.b_id,category.a_id, category.parentname, categoryproduct.childname, categoryproduct.title FROM category LEFT JOIN categoryproduct ON category.a_id = categoryproduct.a_id";

i hv a use this query in above...is a complettly run on mysql database but not performed in php webpage in my design
and genrate look like as a error

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\AdminPanel\menu1.php on line 87

so help me sir plssssssssss

for me it was wrong db name :(

Same problem.
i have a table named jobs. when i execute the query in php myadmin, it returns me 4 rows, but getting an error while using php. tried all that is posted in the forum above. :(

require('db.php');
$result="SELECT * FROM `jobs`;" or die(mysql_error());
echo $result;
while($row=mysql_fetch_array($result,MYSQL_ASSOC))
{
echo $row;
var_dump($row[$j]);
/*some codes here*/
}

i am getting a warning -
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\teerth consultancy\index.php on line 526

stupid of my! didnt use mysql_query...
thanx nywaz all... :)

Hey guys im just testin out a new thing with php and im trying to connect to my database but this error shows up...
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/a5547806/public_html/login.php on line 54

i tried everything else and nothing seems to work...

btw heres lines 53 & 54:

            $query = mysql_query("SELECT * FROM users WHERE username='$user'");
            $numrows = mysql_num_rows($query);

Any help is appreciated.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.