error using mysql_num_rows( )

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Ive got the following code which works great on my localserver, but
when i upload it to my service provider i get an error

"Warning: mysql_num_rows(): supplied argument is not a valid MySQL
result resource in /opt2/home3/mitas/public_html/register.php on line

It seems to be only this function mysql_num_rows() causing a problem,
and the rest of the code works ok, and it adds data correctly.

I have checked with the provider, and they are using
PHP 4.3.10
mySQL 4.0.26

While im using
PHP 5.12
mySQL 5.0.15

Im wondering is this function supported by the older versions ?
Or any other ideas.

82 $conn=@mysql_connect( "myServer", "myUser", "myPassword" ) or die(
"Err:Conn" );
83 $rs = @mysql_select_db( "myDatabase", $conn) or die( "Err:Db" );

84 $sql="SELECT eMail FROM tblusers WHERE eMail=\"$eMail\" ";
85 $rs=mysql_query($sql,$conn);
86 $mRecLen=mysql_num_rows($rs);
87 if ($mRecLen>=1)  {
88 exit("Sorry,the record exists try another" );
89 }

END CODE----------------------------------------------------


Re: error using mysql_num_rows( )

Fish44 wrote:
Quoted text here. Click to load it

It means it exactly what it says - $rs is not a valid resource, which
means the line that gives $rs has failed.

echo mysql_error() after every MySQL call, to find out what the problem

P.S. You probably want to put quotes around the e-mail address in the
query, and also call mysql_real_escape_string() on $eMail.


Re: error using mysql_num_rows( )

Try :

$sql="SELECT eMail FROM tblusers WHERE eMail='$eMail' ";

Re: error using mysql_num_rows( )

If you do not have a valid resource you will always get an error.

Try catching your resource in an "if" statement.

If($rs) {
do this....
} else {
do something else...

If nothing is selected and there are no matching rows you will
not get a valid resource.

Oli Filth wrote:
Quoted text here. Click to load it

Re: error using mysql_num_rows( )

Thanks for all the replies. The problem was an obvious one and i should
have picked it up.
It was the case was incorrect in some table names.

Worked fine local (windows apache), but when i put it on my website,
(apache / Linux) case was important.
Oli your advice was spot on, espacially the mysql_errror|() function
which gave me the name of the table at fault.

Site Timeline