-2

I have something like this

  $result = $conn->query("DELETE FROM agendas WHERE agendaID='" . $_GET["delete"] . "'");

Where $_GET["delete"] is the id that I just received with GET.

I want to ask the user if he wants to delete or not, but not sure how to implement getting his input.

I was thinking about using 2 links, but not sure how to pass the answer, since then they can do whatever they want.

echo '<a href="url">Yes</a>';
echo '<a href="url">No</a>';
George Irimiciuc
  • 4,573
  • 8
  • 44
  • 88

3 Answers3

0

Instead of sending a delete query to the database, generate an HTML form and send it to the browser.

If the user clicks the "Yes" submit button, then construct that query and run it.

(You'll need to pass through all the identifying data you need in hidden inputs).

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

you can ask conformation like below:

<form onSubmit="return confirm('Are you sure you want to delete?')">
<button type="submit" ...>
</form>

REFER: Delete button and confirmation

Community
  • 1
  • 1
Mani
  • 888
  • 6
  • 19
0

Suppose it's a link the user is clicking on to delete, like so:

<a href="/delete.php?id=43">Delete</a>

The easiest way would be to use the Javascript confirm() method:

<a href="/delete.php?id=43" onclick="return confirm('Are you sure you wish to delete?')">Delete</a>

Another way would be to create a new document which the delete link points to. In this document you output a delete confirmation question to the user and the option to proceed to the actual script that deletes, or a cancel link which takes the user back to where he came from.

EDIT: Beware of SQL-injection attacks which your code is vulnerable to. See Quentin's comment above.

HaukurHaf
  • 13,522
  • 5
  • 44
  • 59