I'm trying to create a simple PHP page that retrieves and shows the information from the DB, so I do this, which works fine:
echo "<form action='#' method='post'>";
if(!empty($result)){
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
echo "<td><input type = 'hidden' name = 'value_id' id = 'value_id' value = '" . $row['id'] . "'/></td>";
echo "<td><input type = 'text' name = 'name_value' id = 'name_value' value = '" . $row['name'] . "'/></td>\n";
echo "<td><input type = 'text' name = 'addr_value' id = 'addr_value' value = '" . $row['addr'] . "'/></td>\n";
echo "<td><INPUT type='submit' name = 'modifyItem' value ='Modify'></td>\n";
echo "<td><INPUT type='submit' name = 'deleteItem' value ='Delete'></td>\n";
echo "\t</tr>\n";
}
}
echo "</form>";
Every row has a delete button, which will allow the user to delete each row individually, so I see if the delete button has been clicked and I proceed to remove the row by getting the ID:
if(isset($_POST['deleteItem'])){
$querydelete = "DELETE FROM address WHERE ID = " . $_POST["value_id"];
mysql_query($querydelete) or die('Query failed: ' . mysql_error());
}
The problem is that the ID value is always the same after after the post (which is the ID value of the last row). If I show the ID beforehand for each row, it's the correct one, so the problem must be the value it's getting in the post. What am I doing wrong?