Hi.
i want to ask why my coding for my key-list.php have and error even though i copied the same coding with staff-list.php. When i run the staff-list theres got no error and it can display. But, when it comes to key-list.php the error comes out like this 'Fatal error: Call to a member function fetch_array() on a non-object in C:\xampp\htdocs\belajar\admin\key-list.php on line 33'. Any one know what is wrong with my key-list.php coding. I had check the error but the error still the same.
Code of staff-list.php:
<?php
include('../config.php');
$sql_staff = "SELECT * FROM staff";
if($result_staff = $connect->query($sql_staff))
{
$rows_staff = $result_staff->fetch_array();
$total_staff = $result_staff->num_rows;
$num_staff = 0;
}
?>
<h2>Staff Record</h2>
<table border="1" width="100%">
<tr>
<td>Staff ID</td>
<td>Staff Name</td>
<td>Staff Email</td>
<td>Staff Phone</td>
<td>Action</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $rows_staff['staff_id'];?></td>
<td><?php echo $rows_staff['staff_name'];?></td>
<td><?php echo $rows_staff['staff_email'];?></td>
<td><?php echo $rows_staff['staff_phone'];?></td>
<td>
<a href="delete-staff.php?staff_id=<?php echo $rows_staff['staff_id'];?>">Delete</a>
<a href="view-staff.php?staff_id=<?php echo $rows_staff['staff_id'];?>">View</a>
<a href="edit-staff.php?staff_id=<?php echo $rows_staff['staff_id'];?>">Edit</a>
</td>
</tr>
<?php } while($rows_staff = $result_staff->fetch_array()); ?>
</table>
Code for key-list.php :
<?php
include('../config.php');
$sql_key = "SELECT * FROM key";
if($result_key = $connect->query($sql_key))
{
$rows_key = $result_key->fetch_array();
$total_key = $result_key->num_rows;
$num_key = 0;
}
?>
<h2>Key Record</h2>
<table border="1" width="100%">
<tr>
<td>Key ID</td>
<td>Room Key</td>
<td>Person In-Charge</td>
<td>Action</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $rows_key['key_id'];?></td>
<td><?php echo $rows_key['room_name'];?></td>
<td><?php echo $rows_key['pic_bilik'];?></td>
<td>
<a href="delete-key.php?key_id=<?php echo $rows_key['key_id'];?>">Delete</a>
<a href="view-key.php?key_id=<?php echo $rows_key['key_id'];?>">View</a>
<a href="edit-key.php?key_id=<?php echo $rows_key['key_id'];?>">Edit</a>
</td>
</tr>
<?php } while($rows_key = $result_key->fetch_array()); ?>
</table>
I need some help in this. Thank you in advanced.