Jump to content

Error mysql_num_rows() expects parameter 1 to be resource


merpati

Recommended Posts

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******

 

 ?>

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?

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.