I want to delete a row in mysql database by Javascript confirmation box.
<?php
$select_items= mysql_query("SELECT * FROM items");
$row_select_items= mysql_fetch_array($select_items)
extract($row_select_items);
$db_item_id=$row_select_items['db_item_id'];
echo "<a href=\"index.php?type=delete&value=$db_item_id\">Delete</a>";
?>
As soon as user click on "Delete" link, I want to get a javascript confirm box to confirm the deletion. If it yes delete the row with certain id, if it no just close the pop up box.
-
Do you need PHP or JS code for that?hogan– hogan2015年07月01日 00:30:24 +00:00Commented Jul 1, 2015 at 0:30
-
He needs both. And probably he needs to understand that Javascript runs on the client (browser) whereas PHP runs on the server. So he needs a Javascript that when confirmed sends a request to the server where this PHP delete code is executed.Alexander– Alexander2015年07月01日 07:39:29 +00:00Commented Jul 1, 2015 at 7:39
1 Answer 1
In the link you can add:
"<a href=\"index.php?type=delete&value=$db_item_id\" onclick=\"return confirm('Are you sure?');\">Delete</a>";
answered Jul 1, 2015 at 0:15
Josep Valls
5,6103 gold badges39 silver badges70 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
hogan
I'd go with that answer, too. Please make sure that you check on the backend whether the user is allowed to delete that item or people could just call all id's and delete all items.
default