I’m new to PHP, so please pardon me for anything stupid.
I’m creating a phonebook (as my first PHP project) with the ability to delete an entry from the database.
Here’s my code:
<?php for ($i = 0; $i < count($entries); $i++) { ?>
<tr <?php echo ($i % 2) ? "class='alt'" : ""; ?>>
<td><?php echo "0" . $entries[$i]["id"] . "."; ?></td>
<td><?php echo $entries[$i]["name"]; ?></td>
<td><?php echo "+92" . $entries[$i]["number"]; ?></td>
<td>
<form action="delete.php" method="post">
<input type="submit" value="Delete" id="delete">
</form>
</td>
</tr>
<?php } ?>
Question: How do I “POST” the ID ($entires[i$]["id"]) to delete.php?
You can use a hidden input to post the id.
Just put the form around your
<table />and add the hidden input to the<td />that already contains the id.