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

Closed Thread

Join Date: Mar 2008
Posts: 5
Reputation: bigvic718 is an unknown quantity at this point 
Solved Threads: 0
bigvic718 bigvic718 is offline Offline
Newbie Poster

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

 
0
  #41
Mar 10th, 2008
I am having the same problem as the original guy for my database code....can someone help please? here is the code.

  1. <body>
  2. <?php
  3.  
  4. include("../misc.inc");
  5. mysql_connect($host,$user,$pass);
  6. mysql_select_db($database);
  7. if($HTTP_GET_VARS['id'])
  8. {
  9. $query = "SELECT * FROM guestlist WHERE eventID = '".$HTTP_GET_VARS['id']."'";
  10. $result = mysql_query($query);
  11. $nrows = mysql_num_rows($result);
  12. if($nrows > 0){
  13. $i = 0;
  14. $myGuests = array();
  15. while($row = mysql_fetch_array($result))
  16. {
  17. extract($row);
  18. $totalGuests += $guests;
  19. $myGuests[$i] = "<tr><td>".($i+1)."</td><td>$guestName</td><td>$guests</td><td>$email</td></tr>";
  20. $i++;
  21. }
  22. echo "<p>$nrows on guestlist, ".($nrows+$totalGuests)." expected for event.</p>";
  23. echo "<table width =\"600\" border=\"1\">";
  24. echo "<tr><th>&nbsp;</th><th>Name</th><th width=\"50\">Guests</th><th>Email</th></tr>";
  25. for($i=0;$i<sizeof($myGuests);$i++)
  26. {
  27. echo $myGuests[$i];
  28. }
  29. echo "</table>";
  30. }
  31. else
  32. {
  33. echo "<p>No guests.</p>";
  34. }
  35. }
  36. else
  37. {
  38. $currentDate = date("Y-m-d",time());
  39. $query = "SELECT * FROM events_entries WHERE eventDate >= '$currentDate' ORDER by eventDate";
  40. $result = mysql_query($query);
  41. $nrows = mysql_num_rows($result);
  42. while($row = mysql_fetch_array($result))
  43. {
  44. extract($row);
  45. echo "<p>-<a href=\"getguests.php?id=$id\">$eventDate: $eventName @ $eventLocation</a></p>";
  46. }
  47. }
  48.  
  49. ?>
  50. <p>-<a href="index.php?<?php echo session_id(); ?>">Back To Main</a><br />
  51. -<a href="logout.php?<?php echo session_id(); ?>">Logout</a></p>
  52. </body>

I am getting these 2 error messages:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
Please advise....thanks a lot guys!!
Last edited by peter_budo; Apr 3rd, 2008 at 11:12 am. Reason: Keep It Organized - please use [code] tags
Quick reply to this message  
Join Date: Apr 2008
Posts: 1
Reputation: qamarneo is an unknown quantity at this point 
Solved Threads: 0
qamarneo qamarneo is offline Offline
Newbie Poster

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

 
0
  #42
Apr 3rd, 2008
i got this error plz tell me what is main problem in code

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\login\checklogin.php on line 34
Wrong Username or Password
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <title>Untitled Document</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. </head>
  7.  
  8. <body>
  9. <?php
  10. $host="localhost"; // Host name
  11. $username="root"; // Mysql username
  12. $password=""; // Mysql password
  13. $db_name="test"; // Database name
  14. $tbl_name="members"; // Table name
  15.  
  16. // Connect to server and select databse.
  17. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  18. mysql_select_db("$db_name")or die("cannot select DB");
  19.  
  20. // username and password sent from form
  21. $myusername=$_POST['myusername'];
  22. $mypassword=$_POST['mypassword'];
  23.  
  24. // To protect MySQL injection (more detail about MySQL injection)
  25. $myusername = stripslashes($myusername);
  26. $mypassword = stripslashes($mypassword);
  27. $myusername = mysql_real_escape_string($myusername);
  28. $mypassword = mysql_real_escape_string($mypassword);
  29.  
  30. $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
  31. $result=mysql_query($sql);
  32.  
  33. // Mysql_num_row is counting table row
  34. $count=mysql_num_rows($result);
  35. // If result matched $myusername and $mypassword, table row must be 1 row
  36.  
  37. if($count==1){
  38. // Register $myusername, $mypassword and redirect to file "login_success.php"
  39. session_register("myusername");
  40. session_register("mypassword");
  41. header("location:login_success.php");
  42. }
  43. else {
  44. echo "Wrong Username or Password";
  45. }
  46. ?>
  47.  
  48.  
  49. </body>
  50. </html>
Last edited by peter_budo; Apr 3rd, 2008 at 11:13 am. Reason: Keep It Organized - please use [code] tags
Quick reply to this message  
Join Date: Nov 2007
Posts: 3,761
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

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

 
0
  #43
Apr 3rd, 2008
There is something wrong with your query. Print out your query (print $sql ) and tell us what does it print.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Quick reply to this message  
Join Date: Jun 2008
Posts: 1
Reputation: michael.mckee is an unknown quantity at this point 
Solved Threads: 0
michael.mckee michael.mckee is offline Offline
Newbie Poster

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

 
0
  #44
Jun 10th, 2008
Hello, I'm new to html not to even mention mysql. I've gotten roped into keeping the company website updated and have run into an error:

  1. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/thesoun1/public_html/used.php on line 206
  2.  
  3. Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/thesoun1/public_html/used.php on line 325

Here is the code for the database query:

  1. <td valign="top" colspan="3"><img src="/images/clearpixel.gif" width="15">
  2. <center><table align="center" border="2" cellpadding="2" cellSpacing="2" bgcolor="#63c6de">
  3. <tr>
  4.  
  5. <?php
  6.  
  7. $user = 'thesoun1_dbuser';
  8. $pass = 'dbuserpw';
  9. $host = 'localhost';
  10. $db_name = 'thesoun1_soundwave';
  11.  
  12.  
  13. $dbc = @mysql_connect($host, $user, $pass) or die ('Could not connect to database ' . mysql_error());
  14.  
  15. @mysql_select_db ($db_name) or die ('Could not select the database ' . mysql_error());
  16.  
  17. //echo 'Database connection succeded and table ' . $db_name . ' was selected OK.';
  18.  
  19. $query = "select * from inventory where condition = 'used' order by brand asc";
  20.  
  21. $result = @mysql_query($query);
  22. $num_rows = mysql_num_rows($result);
  23.  
  24. if($result)
  25. {
  26. // echo '<td>';
  27. echo "<tr>
  28. <td align=\"center\"><font color=\"BLUE\">Brand</td>
  29. <td align=\"center\"><font color=\"BLUE\">Model</td>
  30. <td align=\"center\"><font color=\"BLUE\">Serial</td>
  31. <td align=\"center\"><font color=\"BLUE\">Category</td>
  32. <td align=\"center\"><font color=\"BLUE\">Condition</td>
  33. <td align=\"center\"><font color=\"BLUE\">MSRP</td>
  34. <td align=\"center\"><font color=\"BLUE\">Price</td>
  35. <td align=\"center\"><font color=\"BLUE\">Comments</td>
  36. <td align=\"center\"><font color=\"BLUE\">Website</a></td>
  37. <td align=\"center\"><font color=\"BLUE\">Images</a></td>
  38. <td align=\"center\"><font color=\"BLUE\">Sales</a></td>
  39. <td align=\"center\"><font color=\"BLUE\">Buy</a></td>
  40. </tr>\n";
  41.  
  42.  
  43. while($row = mysql_fetch_array($result, MYSQL_NUM))
  44. {
  45. echo "<tr>
  46. <td align=\"left\" bgcolor=\"LIGHTYELLOW\">$row[1]</td>
  47. <td align=\"left\" bgcolor=\"LIGHTYELLOW\">$row[2]</td>
  48. <td align=\"left\" bgcolor=\"LIGHTYELLOW\">$row[3]</td>
  49. <td align=\"left\" bgcolor=\"LIGHTYELLOW\">$row[4]</td>
  50. <td align=\"left\" bgcolor=\"LIGHTYELLOW\">$row[5]</td>";
  51. if($row[6] == 0)
  52. {
  53. echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"><p>N/A</p></td>";
  54. }
  55. else
  56. {
  57. $row[6] = number_format($row[6],2);
  58. echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\">$row[6]</td>";
  59. }
  60.  
  61. if($row[7] == 0)
  62. {
  63. echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"><p>call</p></td>";
  64. }
  65. else
  66. {
  67. $row[7] = number_format($row[7],2);
  68. echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\">$row[7]</td>";
  69. }
  70.  
  71. echo "<td align=\"left\" bgcolor=\"LIGHTYELLOW\">$row[8]</td>";
  72.  
  73. if($row[9] != "")
  74. {
  75. echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"><a href=\"javascript:website_window('$row[9]',800,600);\" onmouseover=\"if(Rollover) document['web$row[0]'].src=WEBMover.src\" onmouseout=\"if(Rollover) document['web$row[0]'].src=WEBMout.src\"><img src=\"/images/website.gif\" border=\"0\" name=\"web$row[0]\"></a></td>";
  76. }
  77. else
  78. {
  79. echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"><p>N/A</p></td>";
  80. }
  81.  
  82. if($row[10] != "")
  83. {
  84. $linknumber=1;
  85. $loopcount=0;
  86. $gallery = explode(' ',$row[10]);
  87. // $arr_count = sizeof($gallery);
  88. echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\">";
  89. foreach($gallery as $imgname)
  90. {
  91. echo "<a href=\"javascript:create_window('$imgname',5,5);\" class=linkcolor>$linknumber</a>&nbsp;";
  92. ++$linknumber;
  93. ++$loopcount;
  94. if($loopcount == 3)
  95. {
  96. echo "<br>";
  97. $loopcount=0;
  98. }
  99. }
  100. echo "</td>";
  101. // echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"><a href=\"/images/$row[10]\" class=linkcolor>Image</a></td>";
  102. }
  103. else
  104. {
  105. echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"><a href=\"javascript:new_window('/no_images.html',500,400);\" onmouseover=\"if(Rollover) document['noimage$row[0]'].src=NO_IMAGESMover.src\" onmouseout=\"if(Rollover) document['noimage$row[0]'].src=NO_IMAGESMout.src\"><img src=\"/images/noimages.gif\" border=\"0\" name=\"noimage$row[0]\"></a></td>";
  106. // echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"><p>N/A</p></td>";
  107. }
  108.  
  109. if($row[12] != 0)
  110. {
  111. echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"><a href=\"javascript:new_window('/sale_restrictions.html',500,400);\" onmouseover=\"if(Rollover) document['sales$row[0]'].src=R_SALESMover.src\" onmouseout=\"if(Rollover) document['sales$row[0]'].src=R_SALESMout.src\"><img src=\"/images/rs.gif\" border=\"0\" name=\"sales$row[0]\"></a></td>";
  112. }
  113. else
  114. {
  115. echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"></td>";
  116. // echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"><a href=\"javascript:new_window('/nosale_restrictions.html',500,400);\" onmouseover=\"if(Rollover) document['sales$row[0]'].src=NS_SALESMover.src\" onmouseout=\"if(Rollover) document['sales$row[0]'].src=NS_SALESMout.src\"><img src=\"/images/ns.gif\" border=\"0\" name=\"sales$row[0]\"></a></td>";
  117. }
  118.  
  119. if($row[7] != 0)
  120. {
  121. if($row[13] == 1)
  122. {
  123. echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"><a href=\"/cart.php?pid=$row[0]&do=Add\" onmouseover=\"if(Rollover) document['cart$row[0]'].src=CARTMover.src\" onmouseout=\"if(Rollover) document['cart$row[0]'].src=CARTMout.src\"><img src=\"/images/addtocartgreen.gif\" border=\"0\" name=\"cart$row[0]\"></a></td>";
  124. }
  125. else
  126. {
  127. echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"></td>";
  128. // echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"><a href=\"javascript:new_window('/sale_restrictions.html',500,400);\" onmouseover=\"if(Rollover) document['cart$row[0]'].src=RS_SALESMover.src\" onmouseout=\"if(Rollover) document['cart$row[0]'].src=RS_SALESMout.src\"><img src=\"/images/rsales.gif\" border=\"0\" name=\"cart$row[0]\"></a></td>";
  129. }
  130. }
  131. else
  132. {
  133. echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"></td>";
  134. }
  135.  
  136.  
  137. echo "</tr>\n";
  138. }
  139. }
  140. // echo '</td>';
  141. mysql_free_result($result);
  142.  
  143.  
  144. //echo '<br>Got ' . $num_rows . ' records from database.';
  145. mysql_close($dbc);
  146.  
  147. ?>
Quick reply to this message  
Closed Thread

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 177834 | Replies: 43
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC