| | |
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2008
Posts: 5
Reputation:
Solved Threads: 0
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.
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 11:12 am. Reason: Keep It Organized - please use [code] tags
•
•
Join Date: Apr 2008
Posts: 1
Reputation:
Solved Threads: 0
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
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 11:13 am. Reason: Keep It Organized - please use [code] tags
Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
0
#43 Apr 3rd, 2008
•
•
Join Date: Jun 2008
Posts: 1
Reputation:
Solved Threads: 0
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:
Here is the code for the database query:
PHP Syntax (Toggle Plain Text)
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:
PHP Syntax (Toggle Plain Text)
<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); ?>
![]() |
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: Name variable after other variable
Views: 177834 | Replies: 43
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array basic beginner binary broken cakephp checkbox class cms code computing cron curl database date delete directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include indentedsubcategory insert integration ip java javascript joomla jquery limit link login loop mail menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote return script search select server sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube





