What am I doing wrong? The below code is intended to update a single selected record in my database but changes all records?

<?php
$host="localhost";
$username="root";
$password="";
$database="prerentdb";

mysql_connect($host,$username,$password);
mysql_select_db($database) or die( "Unable to select database");

if(!empty($_POST["submit"]))
{
$apt = $_POST['apt'];
$query="SELECT * FROM payments Where apt='$apt'";
$result=mysql_query($query);
if(mysql_num_rows($result))
{
echo "<form action='#' method='post'><b><center>Present Report</center></b><br /><br />
<table border='1'>
<tr>
<th>dep</th>
<th>apt</th>
<th>tenant</th>
<th>month</th>
<th>prev</th>
<th>misc</th>
<th>rent</th>
<th>hud</th>
<th>tenant</th>
<th>amt</th>
<th>date</th>
</tr>
<tr>
<th colspan=2>num</th>
<th>name</th>
<th>chg</th>
<th>bal</th>
<th>amt</th>
<th>due</th>
<th colspan=2>pay</th>
<th colspan=2>paid</th>
</tr>";

while($row = mysql_fetch_assoc($result))
{
echo "<tr>
<td><input type='text' name='dep' value='" . $row['dep'] . "'></td>
<td><input type='text' name='apt' value='" . $row['apt'] . "'></td>
<td><input type='text' name='name' value='" . $row['name'] . "'></td>
<td><input type='text' name='rent' value='" . $row['rent'] . "'></td>
<td><input type='text' name='prevbal' value='" . $row['prevbal'] . "'></td>
<td><input type='text' name='misc' value='" . $row['misc'] . "'></td>
<td><input type='text' name='rentdue' value='" . $row['rentdue'] . "'></td>
<td><input type='text' name='hudpay' value='" . $row['hudpay'] . "'></td>
<td><input type='text' name='tentpay' value='" . $row['tentpay'] . "'></td>
<td><input type='text' name='amtpaid' value='" . $row['amtpaid'] . "'></td>
<td><input type='text' name='datepaid' value='" . $row['datepaid'] . "'></td>
</tr>
<tr>
<td colspan='11' align='center' style='padding-top:20px;'><input type='submit' name='update' value='Update Record'></td>
</tr>";
}
echo "</table>
</form>";
}
else{echo "No listing for appartment $apt.<br />Please select another.<br />";}
}
if(!empty($_POST["update"]))
{
$sql = "UPDATE payments SET dep='".$_POST["dep"]."',apt='".$_POST["apt"]."',name='".$_POST["name"]."',rent='".$_POST["rent"]."',prevbal='".$_POST["prevbal"]."',misc='".$_POST["misc"]."',rentdue='".$_POST["rentdue"]."',hudpay='".$_POST["hudpay"]."',tentpay='".$_POST["tentpay"]."',amtpaid='".$_POST["amtpaid"]."',datepaid='".$_POST["datepaid"]."'";
mysql_query($sql) or die("Update query failed.");
echo "Record for appartment ".$_POST["apt"]." has been updated ...";
}
?>
<form method="post" action="#">
<br />
<input type="text" name="apt"/>
<p>
<input type="submit" name="submit" value="Select Apartment for Payment"/>
</form>