0

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

14
Contributors
14
Replies
26
Views
12 Years
Discussion Span
Last Post by Starfox275
Featured Replies
  • 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, … Read More

0

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.

0

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.

1

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

0

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

0

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';";
0

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>

0

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

0

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

0

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

0

$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

0

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

0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.