-2

The code is working fine with few pages on localhost but this is not working on server and shows some sort warning like "mysql_num_rows() expects parameter 1 to be resource, boolean given in /home2/tp/public_html/ols/admin/delete-employee.php on line 23. It always confuses me because it's working for some page and at some point shows a warning message which frustrates me a lot.

Help please..

<?php
    include('includes/start.php');
    require_once('includes/header.html');
?>
<?php


$page_title = 'View Employees';

require_once("../dbcon.php");
$query = "SELECT
    fname
    , lname
    , eid
    , fname
    , mname
    , lname
    , posid
    , date_added
FROM
    ccse.employee";
$result = @mysql_query($query);
$num = mysql_num_rows($result);
if($num > 0){
  echo "<p align='center'>There are $num employees found on the system!</p>\n";

if($result){

echo '<table align="center" border="1" bgcolor="lightgreen">
<tr>
<td colspan="111" align="center"><b>List of Employees</td></tr>
<tr>
<td align="center"><b>Employee ID</a></b></td>
<td align="center"><b>First Name</a></b></td>
<td align="center"><b>Middle Name</a></b></td>
<td align="center"><b>Last Name</a></b></td>
<td align="center"><b>Position</a></b></td>
<td align="center"><b>Date Added</a></b></td>
<td align="center"><b>Action</a></b></td>
</tr>';

$bg = '#eeeeee';
while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
$bg = ($bg == '#eeeeee' ? '#ffffff' : '#eeeeee');


echo '<tr bgcolor="'.$bg.'">
<td align="left">'.$row['eid'].'</td>
<td align="left">'.$row['fname'].'</td>
<td align="left">'.$row['mname'].'</td>
<td align="left">'.$row['lname'].'</td>
<td align="left">'.$row['posid'].'</td>
<td align="left">'.$row['date_added'].'</td>
<td align="left"><a href="del_emp.php?id='.$row['eid'].'"><img src="../images/delete.jpg" width="50" height="20"></a></td>

</tr>';

}

echo '</table>';
//------------------End of Get list of Employees--------
mysql_free_result($result);
}else{
echo '<p class="error">There are currently no entered employees in the system!</p>';
/*echo '<p class="error">Data Can Not Be Retrieved!</p>';
echo '<p>'.mysql_error().'<br /><br />Query:'.$query.'</p>';*/
}
mysql_close();

if($num_pages > 1){
echo '<br /><p>';
$current_page = ($start/$display) + 1;

if($current_page !=1){
 echo '<a href="profile_emp.php?s='.($start - $display).'&np='.$num_pages.'$sort='.$sort.'" />Previous</a>';
 }

 for($i = 1; $i <=$num_pages; $i++){
  if($i !=$current_page){
  echo '<a href="emp-list.php?s='.(($display * ($i-1))).'&np='.$num_pages.'$sort='.$sort.'" />'.$i.'</a>';
  }else{
  echo $i.'';
  }
 }

 if($current_page !=$num_pages){
 echo '<a href="emp-list.php?s='.($start + $display).'&np='.$num_pages.'$sort='.$sort.'" />Next</a>';
 }
 echo '</p>';
 }
//------End of Paging Result----

}

?>
<?php
echo "<br>";echo "<br>";
include('../includes/footer.html');
?>
Anand Solanki
  • 3,419
  • 4
  • 16
  • 27

1 Answers1

0

The reason MySQL_num_rows is failing is because the $result is probably just false - this happens on a failed query. Use MySQL_error() to find where the error in the query is - could be a bad database, etc, etc - and I also suggest moving away from the MySQL_ functions, as they are deprecated. Use mysqli_ instead.

Helpful
  • 702
  • 4
  • 16