User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 374,546 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,672 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 96727 | Replies: 43
Reply
Join Date: Mar 2008
Posts: 5
Reputation: bigvic718 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
bigvic718 bigvic718 is offline Offline
Newbie Poster

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

  #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 10:12 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote  
Join Date: Apr 2008
Posts: 1
Reputation: qamarneo is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
qamarneo qamarneo is offline Offline
Newbie Poster

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

  #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 10:13 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,045
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 227
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

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

  #43  
Apr 3rd, 2008
There is something wrong with your query. Print out your query (print $sql ) and tell us what does it print.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Jun 2008
Posts: 1
Reputation: michael.mckee is an unknown quantity at this point 
Rep Power: 0
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

  #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:

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

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:

<td valign="top" colspan="3"><img src="/images/clearpixel.gif" width="15">
<center><table align="center" border="2" cellpadding="2" cellSpacing="2" bgcolor="#63c6de">
<tr>

<?php

$user = 'thesoun1_dbuser';
$pass = 'dbuserpw';
$host = 'localhost';
$db_name = 'thesoun1_soundwave';


$dbc = @mysql_connect($host, $user, $pass) or die ('Could not connect to database ' . mysql_error());

@mysql_select_db ($db_name) or die ('Could not select the database ' . mysql_error());

//echo 'Database connection succeded and table ' . $db_name . ' was selected OK.';

$query = "select * from inventory where condition = 'used' order by brand asc";

$result = @mysql_query($query);
$num_rows = mysql_num_rows($result);

if($result)
{
// echo '<td>';
echo "<tr>
<td align=\"center\"><font color=\"BLUE\">Brand</td>
<td align=\"center\"><font color=\"BLUE\">Model</td>
<td align=\"center\"><font color=\"BLUE\">Serial</td>
<td align=\"center\"><font color=\"BLUE\">Category</td>
<td align=\"center\"><font color=\"BLUE\">Condition</td>
<td align=\"center\"><font color=\"BLUE\">MSRP</td>
<td align=\"center\"><font color=\"BLUE\">Price</td>
<td align=\"center\"><font color=\"BLUE\">Comments</td>
<td align=\"center\"><font color=\"BLUE\">Website</a></td>
<td align=\"center\"><font color=\"BLUE\">Images</a></td>
<td align=\"center\"><font color=\"BLUE\">Sales</a></td>
<td align=\"center\"><font color=\"BLUE\">Buy</a></td>
</tr>\n";


while($row = mysql_fetch_array($result, MYSQL_NUM))
{
echo "<tr>
<td align=\"left\" bgcolor=\"LIGHTYELLOW\">$row[1]</td>
<td align=\"left\" bgcolor=\"LIGHTYELLOW\">$row[2]</td>
<td align=\"left\" bgcolor=\"LIGHTYELLOW\">$row[3]</td>
<td align=\"left\" bgcolor=\"LIGHTYELLOW\">$row[4]</td>
<td align=\"left\" bgcolor=\"LIGHTYELLOW\">$row[5]</td>";
if($row[6] == 0)
{
echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"><p>N/A</p></td>";
}
else
{
$row[6] = number_format($row[6],2);
echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\">$row[6]</td>";
}

if($row[7] == 0)
{
echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"><p>call</p></td>";
}
else
{
$row[7] = number_format($row[7],2);
echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\">$row[7]</td>";
}

echo "<td align=\"left\" bgcolor=\"LIGHTYELLOW\">$row[8]</td>";

if($row[9] != "")
{
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>";
}
else
{
echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"><p>N/A</p></td>";
}

if($row[10] != "")
{
$linknumber=1;
$loopcount=0;
$gallery = explode(' ',$row[10]);
// $arr_count = sizeof($gallery);
echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\">";
foreach($gallery as $imgname)
{
echo "<a href=\"javascript:create_window('$imgname',5,5);\" class=linkcolor>$linknumber</a>&nbsp;";
++$linknumber;
++$loopcount;
if($loopcount == 3)
{
echo "<br>";
$loopcount=0;
}
}
echo "</td>";
// echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"><a href=\"/images/$row[10]\" class=linkcolor>Image</a></td>";
}
else
{
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>";
// echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"><p>N/A</p></td>";
}

if($row[12] != 0)
{
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>";
}
else
{
echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"></td>";
// 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>";
}

if($row[7] != 0)
{
if($row[13] == 1)
{
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>";
}
else
{
echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"></td>";
// 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>";
}
}
else
{
echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"></td>";
}


echo "</tr>\n";
}
}
// echo '</td>';
mysql_free_result($result);


//echo '<br>Got ' . $num_rows . ' records from database.';
mysql_close($dbc);

?>
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)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 4:08 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC