php - How do I distinguish between button clicks in a form? -
so i'm creating database website , want create admin section allows add or delete table. here snapshot of want achieve...
in php file have if($_post['delete_category'])
correctly gets delete button clicks, i'm not sure how distinguish delete button clicked. i'm sure simple solution, i'm stuck. thanks!
you can discern button submitted following markup (based on example fetched results db):
<?php if(isset($_post['delete_category'])) { $id = $_post['delete_category']; // value="1" or value="3" goes in here echo $id; } ?> <form method="post" action=""> <table border="1"> <tr> <th>id</th><th>name</th><th>delete</th> </tr> <tr> <td>1</td> <td>senior pictures</td> <td><button typpe="submit" name="delete_category" value="1">delete</button></td> <!-- each delete button has same name, different values --> </tr> <tr> <td>3</td> <td>engagements</td> <td><button typpe="submit" name="delete_category" value="3">delete</button></td> </tr> </table> </form>
if had guess makes sense on fetching: (note: just sample!)
<form method="post" action=""> <table border="1"> <tr> <th>id</th><th>name</th><th>delete</th> </tr> <?php while($row = $results->fetch_assoc()): ?> <!-- assuming mysqli() --> <?php while($row = mysql_fetch_assoc($result)): ?> <!-- assuming on mysql (bleh) --> <tr> <td><?php echo $row['id']; ?></td> <td><?php echo $row['name']; ?></td> <td> <button typpe="submit" name="delete_category" value="<?php echo $row['id']; ?>">delete</button> </td> </tr> <?php endwhile; ?> </table> </form>
Comments
Post a Comment