+ 1

How to delete MySQL entry with PHP

Hello, I'm new at PHP and MySQL, so I need a little bit of help, but i think, it's a simple solved Problem. I have made a MySQL Database and connected it with a PHP Webpage, so that the saved data is shown in a table Element. You can also add new values, everything is working perfectly fine, but i want to add a button after every entry, which says "Delete" and if you click it, the specific entry get's deleted. How can I do that? Thank u ^^ My actual code: <?php include_once 'includes/connect.php'; ?> <html> <title>Online Einkaufszettel v 1.1</title> <style type="text/css"> table { font-size: 40px; text-align: left; width: 40%; margin-top: 2%; } th { text-align: center; } </style> <head> <div id="head"> <h1>Digitaler Einkaufszettel</h1> </div> </head> <body> <center> <table border="2px"> <tr> <th>ID</th> <th>Produkt</th> <th>Menge</th> <th>Aktion</th> </tr> <?php $sql = "SELECT * FROM einkaufszettel;"; $result = mysqli_query($conn, $sql); if ($conn-> connect_error) { die("Ups, das sollte nicht so sein:". $conn-> connect_error); } $sql = "SELECT eintrags_id, produkt, menge from einkaufszettel"; $result = $conn-> query($sql); if ($result-> num_rows > 0) { while ($row = $result-> fetch_assoc()) { echo "<tr><td>". $row["eintrags_id"] ."</td><td>". $row["produkt"] ."</td><td>". $row["menge"] ."</td><td>"."</td></tr>"; } } ?> </table> <p> Produkt hinzufügen </p> <form action="includes/hinzufuegen.php" method="POST"> <input type="text" name="produkt" placeholder="Produkt"> <input type="text" name="menge" placeholder="Menge"> <button type="submit" name="submit">Hinzufügen</button> </form> </center> </body> </html> <link rel="stylesheet" href="style.css"> <li

30th Jun 2020, 1:00 PM
Titus
Titus - avatar
1 Antwort
0
Since nobody has answered yet, I'll give you my guess... I think it should be possible (as far as I know) to place a form-button combination within a table cell. Please check this before proceeding. Would of course be more pretty to have them intended in another column. Then I think you should build the delete statement in your while loop or at least refer to the eintrags_id to post to the script called by button. Everything clear so far?
30th Jun 2020, 4:43 PM
Sandra Meyer
Sandra Meyer - avatar