•
•
•
•
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
![]() |
•
•
Join Date: Mar 2008
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
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.
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!!
php Syntax (Toggle Plain Text)
<body> <?php include("../misc.inc"); mysql_connect($host,$user,$pass); mysql_select_db($database); if($HTTP_GET_VARS['id']) { $query = "SELECT * FROM guestlist WHERE eventID = '".$HTTP_GET_VARS['id']."'"; $result = mysql_query($query); $nrows = mysql_num_rows($result); if($nrows > 0){ $i = 0; $myGuests = array(); while($row = mysql_fetch_array($result)) { extract($row); $totalGuests += $guests; $myGuests[$i] = "<tr><td>".($i+1)."</td><td>$guestName</td><td>$guests</td><td>$email</td></tr>"; $i++; } echo "<p>$nrows on guestlist, ".($nrows+$totalGuests)." expected for event.</p>"; echo "<table width =\"600\" border=\"1\">"; echo "<tr><th> </th><th>Name</th><th width=\"50\">Guests</th><th>Email</th></tr>"; for($i=0;$i<sizeof($myGuests);$i++) { echo $myGuests[$i]; } echo "</table>"; } else { echo "<p>No guests.</p>"; } } else { $currentDate = date("Y-m-d",time()); $query = "SELECT * FROM events_entries WHERE eventDate >= '$currentDate' ORDER by eventDate"; $result = mysql_query($query); $nrows = mysql_num_rows($result); while($row = mysql_fetch_array($result)) { extract($row); echo "<p>-<a href=\"getguests.php?id=$id\">$eventDate: $eventName @ $eventLocation</a></p>"; } } ?> <p>-<a href="index.php?<?php echo session_id(); ?>">Back To Main</a><br /> -<a href="logout.php?<?php echo session_id(); ?>">Logout</a></p> </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
•
•
Join Date: Apr 2008
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
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
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
php Syntax (Toggle Plain Text)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="members"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword"); header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?> </body> </html>
Last edited by peter_budo : Apr 3rd, 2008 at 10:13 am. Reason: Keep It Organized - please use [code] tags
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,045
Reputation:
Rep Power: 8
Solved Threads: 227
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*
*PM asking for help will be ignored*
•
•
Join Date: Jun 2008
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
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:
Here is the code for the database query:
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> ";
++$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);
?>![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
Similar Threads
- Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in (PHP)
- Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource (PHP)
Other Threads in the PHP Forum
- Previous Thread: pagination within image - IF problem
- Next Thread: How insert image into mysql database and retrieve



Linear Mode