Hack Forums
[PHP] [php] delete row with a <button> - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Web Development (https://hackforums.net/forumdisplay.php?fid=183)
+---- Thread: [PHP] [php] delete row with a <button> (/showthread.php?tid=6085823)



[php] delete row with a <button> - blackcoder00 - Jun 8, 2020

guys im wonder how can i create some button that delete data from a table i didn't find how could i do it so i have replaced the button with <a> tag ==><a href="edit.php?id= . $$row["name"] for the where condition delete from list where id = '$_GET['name']'
[Image: T31URyT.png]
index.php file
PHP Code

<?php 
$conn 
= mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
 
 die("Connection failed: " . mysqli_connect_error());
}

 
 $sql = "DELETE FROM list where name = '$id'";


if (
mysqli_query($conn, $sql)) {


 
 echo "succes delete you can back <a href='index.php' back </a>";

 
 
} else {
 
 echo "_error_: " . $sql . "<br>" . mysqli_error($conn);
} 

updatetable.php file
PHP Code

<?php 
 while
($row = mysqli_fetch_assoc($result)) {
 
   echo "<tr><td>"."<a href='php/updatetable.php?id=" . $row["name"]. " </a></td><td> " . $row["description"]. "</td><td> " . $row["matiere"]. "</td><td>".$row["date"]."</td><td>".$row["jour"]."</td><td>".$row["time"]."</td></tr></form>";
 
 }
} else {
 
 echo "0 results";
}
echo
"</tbody></table></div>";

?>



RE: [php] delete row with a <button> - HFDone - Jun 8, 2020

delete the row in the db and load the table again


RE: [php] delete row with a <button> - blackcoder00 - Jun 8, 2020

i want to create a buttuon to select a specific item to delete it in the table


RE: [php] delete row with a <button> - HFDone - Jun 8, 2020

so add button and onclick put the code to delete it and load the table again


RE: [php] delete row with a <button> - blackcoder00 - Jun 8, 2020

(Jun 8, 2020 01:20 PM)HFDone Wrote:  so add button and onclick put the code to delete it and load the table again

can you show me some example please


RE: [php] delete row with a <button> - HFDone - Jun 9, 2020

search for html table delete row by id


RE: [php] delete row with a <button> - Squito - Jun 9, 2020

https://stackoverflow.com/questions/2906582/how-to-create-an-html-button-that-acts-like-a-link


RE: [php] delete row with a <button> - blackcoder00 - Jun 9, 2020

(Jun 9, 2020 04:46 AM)Squito Wrote:  https://stackoverflow.com/questions/2906582/how-to-create-an-html-button-that-acts-like-a-link

dude i want to create a button that delete a specific row from database like the example in the picture


RE: [php] delete row with a <button> - Squito - Jun 9, 2020

And I provided a solution, that you have to change slightly to work the way you want it. If I do it all for you, you are going to miss the 'figuring out' part of the process, which is eventually a bad thing.


RE: [php] delete row with a <button> - HFDone - Jun 9, 2020

https://stackoverflow.com/a/46325093


RE: [php] delete row with a <button> - blackcoder00 - Jun 9, 2020

(Jun 9, 2020 08:16 AM)Squito Wrote:  And I provided a solution, that you have to change slightly to work the way you want it. If I do it all for you, you are going to miss the 'figuring out' part of the process, which is eventually a bad thing.

thank you alot dude i will try it <3


RE: [php] delete row with a <button> - Backbone - Jun 9, 2020

I do it like this.
On table:
Code
- loop on result
- get the row id
- placed the row id on a href link of delete button

Example: <a href="?action=delete&id=ROW_ID">Delete</a>

On back-end code:
Code
- Check for the action and id query param
- Do the delete query using the id query param



RE: [php] delete row with a <button> - blackcoder00 - Jun 10, 2020

(Jun 9, 2020 07:39 PM)Backbone Wrote:  I do it like this.
On table:
Code
- loop on result
- get the row id
- placed the row id on a href link of delete button

Example: <a href="?action=delete&id=ROW_ID">Delete</a>

On back-end code:
Code
- Check for the action and id query param
- Do the delete query using the id query param

your idea is pretty good thank you aloot


RE: [php] delete row with a <button> - DyMa - Jun 12, 2020

(Jun 10, 2020 10:26 AM)blackcoder00 Wrote:  your idea is pretty good thank you aloot

friendly reminder to use prepared statement for this