RSS Forums RSS
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 476 | Replies: 3 | Thread Tools  Display Modes
Reply
Join Date: Oct 2007
Posts: 2
Reputation: ta5na is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ta5na ta5na is offline Offline
Newbie Poster

PHP errors

  #1  
Oct 24th, 2007
Hello experts,

I'm having some difficults with the code that i have used from one of the PHP, MySQL books. As the error that appears is in bold on line 17, and the error that shows is listed below:

"Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\Testing PHP with MySQL uses online Tutorials\Testing_with_MySQL_Database.php on line 17"

  1. <html>
  2. <body>
  3.  
  4. <?php
  5. //Open connection to MySQL server
  6. $connection = mysql_connect('localhost','root') or die ('Unable to connect!');
  7.  
  8. // select database for use
  9. mysql_select_db('movies') or die ('Unable to select database!');
  10.  
  11. // create and execute query
  12. $query = 'SELECT * FROM movies';
  13. $result = mysql_query($query)
  14. or die ('Error in query: $query. ' . mysql_error());
  15.  
  16. // check if records were returned
  17. if (mysql_num_rows(Sresult) > 0)
  18. {
  19. //Print HTML table
  20. echo '<table width = 100% cellpadding=10 cellspacing=0 border=1>';
  21. echo
  22. '<tr><td><b>Customer ID/b</td><tr><td><b>Customer Full Name/b</td><tr><td><b>Date Of Birth/b</td>';
  23.  
  24. // iterate over record set
  25. // print each field
  26. while($row = mysql_fetch_row($result))
  27. {
  28. echo '<tr>';
  29. echo '<td>' . $row[0] . '</td>';
  30. echo '<td>' . $row[1] . '</td>';
  31. echo '<td>' . $row[2] . '</td>';
  32. echo '</tr>';
  33. }
  34. echo '</table>';
  35. }
  36. else
  37. {
  38. // print error message
  39. echo 'No rows found!';
  40. }
  41.  
  42. // once processing is complete
  43. // free result set
  44. mysql_free_result($result);
  45.  
  46. //close connection to MySQL server
  47. mysql_close($connection);
  48. ?>
  49.  
  50. </body>
  51. </html>


Please help,

Thanks,
Mitesh
Last edited by ta5na : Oct 24th, 2007 at 10:41 am. Reason: please use code tags when posting code
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2007
Location: Israel
Posts: 16
Reputation: Shaffer is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
Shaffer Shaffer is offline Offline
Newbie Poster

Re: PHP errors

  #2  
Oct 24th, 2007
Hello,
it says Sresult, instead of $result. It's just not a MySQL result, not a PHP variable.

Shaffer.
Reply With Quote  
Join Date: Oct 2007
Posts: 2
Reputation: ta5na is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ta5na ta5na is offline Offline
Newbie Poster

Question Re: PHP errors

  #3  
Oct 24th, 2007
Hello,

What a stupid mistake i made, i was sitting here for a good 20mins and i was confused!

Thanks alot for you help,
Mitesh
Reply With Quote  
Join Date: Oct 2007
Location: Chenoa, IL
Posts: 13
Reputation: bigattichouse is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
bigattichouse's Avatar
bigattichouse bigattichouse is offline Offline
Newbie Poster

Re: PHP errors

  #4  
Oct 25th, 2007
Originally Posted by ta5na View Post

if (mysql_num_rows(Sresult) > 0)


Should be

if (mysql_num_rows($result) > 0)
Need a simple, powerful knowledgebase? Bigattichouse Knowledge Base finds the solution while you're still typing the problem.
http://www.bigattichouse.com/knowledgebase.html
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:10 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC