I am trying to update whatever content in the textbox that has been edited and post to database. However, only the second record is update but the first record is not. I think should be the while loop problem but I don't what is the mistake. Here's my edit page code: viewadmindb.php
<?php
session_start();
include('adminconfig.php');
$sql = "SELECT * FROM admin ORDER BY ID";
$result = mysql_query($sql);
?>
<body>
<div id="wrap">
<div id="status"></div>
<form method="POST" action="adminsave.php" onSubmit="return validate(this);">
<table class="viewdb" contentEditable="true">
<tr><td id='fcolor' style='border:2px solid black' align=center> ID </td>
<td id='fcolor' style='border:2px solid black' align=center> Name </td>
<td id='fcolor' style='border:2px solid black' align=center> Password </td>
<td id='fcolor' style='border:2px solid black; width:auto;' align=center> Department </td>
<td id='fcolor' style='border:2px solid black' align=center> Email </td></tr>
<div id="content">
<?php
while($row = mysql_fetch_array($result)){ ?>
<tr>
<td style='border:2px solid black; width:auto' align=center><?php echo $row['ID'] ?> </td>
<td style='border:2px solid black' align=center> <?php echo $row['name'] ?> </td>
<td style='border:2px solid black' align=center> <?php echo $row['password'] ?> </td>
<td style='border:2px solid black; width:200px' align=center> <?php echo $row['department'] ?> </td>
<td style='border:2px solid black' align=center> <?php echo $row['email'] ?> </td>
<tr>
<td><input id='edit' type = 'text' name="ID[]" value='<?php echo ($row['ID']); ?>' maxlength="50"/></td>
<td><input id='edit' type = 'text' name="name[]" value='<?php echo $row['name'] ?>' maxlength="50"></td>
<td><input id='edit' type = 'text' name="password[]" value='<?php echo $row['password'] ?>' maxlength=50"></td>
<td><input id='edit' type = 'text' name="department[]" value='<?php echo $row['department'] ?>' maxlength="50"></td>
<td><input id='edit' type = 'text' name="email[]" value='<?php echo $row['email'] ?>' style='width:300px' " maxlength="50"></td>
<?php } ?>
<td><input id='edit' type='submit' name='submit' value='Submit' /></td></tr>
</table>
</form>
<?php
$ID=$row['ID'];
$name=$row['name'];
$password=$row['password'];
$department=$row['department'];
$email=$row['email'];
?>
adminsave.php
<?php
session_start();
include('adminconfig.php');
$ID=$_POST['ID'];
$name=$_POST['name'];
$password=$_POST['password'];
$department=$_POST['department'];
$email=$_POST['email'];
$sql = "UPDATE `admin` SET `name` = '{$name}', `password` = '{$password}', `department` = '{$department}', `email` = '{$email}' WHERE `ID` = '{$ID}'";
$result = mysql_query($sql);
if(!$result){
die('invalid query:'.mysql_error());
}
else
echo ("<tr><td>" . "Data updated succesfully..." . "</td></tr>");
header('Refresh:5; url=viewadmindb.php');
die;
?>