merpati Posted May 9, 2014 Share Posted May 9, 2014 if(isset($_POST['submit'])) { $bil = 1; $id_month = isEmptyField($_POST['id_month']); $id_location = isEmptyField($_POST['loc']); $query="Select * from stock where id_location=$id_location and id_month=$id_month"; $run=mysql_query( $query); $numrows = mysql_num_rows($run); ******error here****** if($numrows == 0) { echo "No results found."; } else { while($row = mysql_fetch_array($run1, MYSQLI_ASSOC)){ echo "<tr>"; echo "<td> $bil </td>"; echo "<td>" . $row['partnumber'] . "</td>"; echo "<td >" . $row['stockIn'] . "</td>"; echo "<td>" . $row['stockOut' ]. "</td>"; echo "<td >" . $row['id_month' ]. "</td>"; echo "<td >" . $row['id_location'] . "</td>"; echo "<td >" . $row['status'] . "</td>"; echo "</tr>"; } } echo " </thead>"; echo "</table>"; ?> <?php $bil++; } mysql_free_result($run); ******error here****** ?> Quote Link to comment https://forums.phpfreaks.com/topic/288362-error-mysql_num_rows-expects-parameter-1-to-be-resource/ Share on other sites More sharing options...
trq Posted May 9, 2014 Share Posted May 9, 2014 Your query is failing for some reason and $run is the bool false, not what mysql_num_rows expects. Always check your queries succeed before using the value they return. Quote Link to comment https://forums.phpfreaks.com/topic/288362-error-mysql_num_rows-expects-parameter-1-to-be-resource/#findComment-1478851 Share on other sites More sharing options...
richei Posted May 9, 2014 Share Posted May 9, 2014 (edited) The error is in the query. You need to put single quotes around strings. Php has a built in function to find empty fields - empty(). Not sure where u got what ur using. Also need to choose one, either use myself or mysqli, can't use both. And where is $ run1 coming from? Edited May 9, 2014 by richei Quote Link to comment https://forums.phpfreaks.com/topic/288362-error-mysql_num_rows-expects-parameter-1-to-be-resource/#findComment-1478852 Share on other sites More sharing options...
cyberRobot Posted May 9, 2014 Share Posted May 9, 2014 The error is in the query. You need to put single quotes around strings. Strings can have either single or double quotes around them. However, double quotes are needed if the string contains something PHP needs to expand like a variable. More information about strings can be found here: http://www.php.net/manual/en/language.types.string.php Also need to choose one, either use myself or mysqli, can't use both. I may have missed it, but I don't see where the OP (merpati) is using MySQLi. They all look to be regular MySQL functions. Of course, the OP should consider using something other than mysql_* functions since they are deprecated (http://www.php.net/manual/en/mysqlinfo.api.choosing.php). He/she may already be looking into that though. And where is $ run1 coming from? That's a good point. I would imagine that's supposed to be $run. @merpati - have you tried using mysql_error() to see if there are any SQL errors being reported? More information can be found here: http://www.php.net/manual/en/function.mysql-error.php Quote Link to comment https://forums.phpfreaks.com/topic/288362-error-mysql_num_rows-expects-parameter-1-to-be-resource/#findComment-1478870 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.