472,146 Members | 1,368 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,146 software developers and data experts.

mysql_num_rows(): supplied argument is not a valid MySQL result resource

Hi! I'm completely new to all dev and trying to put a website together using MySQLI and PHP; was running fine until I try to gather the DB content with the following script:

Expand|Select|Wrap|Line Numbers
  1. <?
  2. $username="xxxxxx";
  3. $password="xxxxxx";
  4. $database="maxalien_davidloran";
  5.  
  6. mysql_connect(localhost,$username,$password);
  7. @mysql_select_db($database) or die( "Unable to select database");
  8. $query="SELECT * FROM contacts";
  9.  
  10. $result=mysql_query($query);
  11.  
  12. $num=mysql_num_rows($result);
  13.  
  14.  
  15. mysql_close();
  16.  
  17. echo "<b><center>Database Output</center></b><br><br>";
  18.  
  19. $i=0;
  20. while ($i < $num) {
  21.  
  22. $username=mysql_result($result,$i,"username");
  23. $password=mysql_result($result,$i,"password");
  24. $email=mysql_result($result,$i,"email");
  25.  
  26. echo "<b>$first $last</b><br>Phone: $phone<br>Mobile: $mobile<br>Fax: $fax<br>E-mail: $email<br>Web: $web<br><hr><br>";
  27.  
  28. $i++;
  29. }
  30.  
  31. ?>
  32.  
getting the following error mesg when running it:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/maxalien/public_html/davidloran/test/userCake/dbresult.php on line 12
Database Output

Let me know if you need more info and thx for your help
Jan 2 '10 #1

✓ answered by code green

Something is failing here
Expand|Select|Wrap|Line Numbers
  1. mysql_connect(localhost,$username,$password); 
  2. @mysql_select_db($database) or die( "Unable to select database"); 
  3. $query="SELECT * FROM contacts"; 
  4.  
  5. $result=mysql_query($query); 
  6.  
  7. $num=mysql_num_rows($result); 
  8.  
You can help yourself by removing the error supression '@' and
testing the returns using if() and mysql_error().

Also, further down you are closing the database connection then continuing to use it

2 3061
is anyone able to help please?
Jan 3 '10 #2
code green
1,726 Expert 1GB
Something is failing here
Expand|Select|Wrap|Line Numbers
  1. mysql_connect(localhost,$username,$password); 
  2. @mysql_select_db($database) or die( "Unable to select database"); 
  3. $query="SELECT * FROM contacts"; 
  4.  
  5. $result=mysql_query($query); 
  6.  
  7. $num=mysql_num_rows($result); 
  8.  
You can help yourself by removing the error supression '@' and
testing the returns using if() and mysql_error().

Also, further down you are closing the database connection then continuing to use it
Jan 4 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by David Nikel | last post: by
4 posts views Thread by Fish44 | last post: by
7 posts views Thread by Dejan | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.