if(isset($_SESSION['admin']) == TRUE){echo "<font face='tahoma' color='#ff0000'>ADMIN : ".$_SESSION['admin']." welcome<br></font>";}
$sql="SELECT *  FROM messages WHERE  messages.user_id=" .$_SESSION['userid']. ";";
$result=mysql_query($sql);
$numrows=mysql_num_rows($result);

for the previous code the browser show me this message:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/www/e3lan3.freehostia.com/header.php on line 9‎

and line 9 is the line colored red in the code .. what's the problem here ?
is a newer version of php doesn't support this (mysql_num_rows()) function ?
if so what's the alternative
thanx all
your friend from Egypt

Hi there!

I suspect you have an error in your SQL query. You could insert an echo $sql."<br>"; right before your mysql_query to check, if the query is correct.

Maybe the problem lies with the session, did you call session_start() beforehand?

Hope that helps somewhat. Happy coding! :)

There many possibility for this error :

1. Check your database / tables / user / password with adding this command $result=mysql_query($sql) or die ("Error connect database ( {$sql} )") ; 2. If you got the same problem like before, maybe the type of messages.user_id is char/varchar/text .
In this problem you should add single-quote before and after "(double-quote) , change your command with : $sql="SELECT * FROM messages WHERE messages.user_id=[B]'[/B]" .$_SESSION['userid']. "[B]'[/B];" ;

is it helpful ?

i think your query should look like this:

$sql="SELECT *  FROM messages WHERE  messages.user_id='". $_SESSION['userid']."'";
This article has been dead for over six months. Start a new discussion instead.