0
echo '<td><a href="candidates.php?id=' . $row['candidate_id'] . '">Delete Candidate</a></td>';

How can i add a confirmation message before the data will be deleted? Like asking are you sure

  • javascript popup that cancels the action if the user clicks "cancel": `onclick="return confirm('Are you sure?');` – simlev Aug 15 '17 at 06:46
  • 2
    Or here or in the next confirmation page you should make a POST instead of a GET request. To avoid browsers and search engines auto-deleting your content by accident. – jeroen Aug 15 '17 at 06:47
  • Here is the answer to your problem -> https://stackoverflow.com/questions/18852373/redirect-only-after-confirmation – Jixone Aug 15 '17 at 06:48
  • 1
    You should even be using a form with CSRF token instead of a simple link – smarber Aug 15 '17 at 06:59

2 Answers2

1

Try this

echo '<td><a href="candidates.php?id=' . $row['candidate_id'] . '" onclick="return confirm('Are you sure...?')">Delete Candidate</a></td>';
Zhi Kai
  • 1,549
  • 1
  • 13
  • 31
  • 2
    You really shouldn't be using a link in combination with javascript for a delete action. – jeroen Aug 15 '17 at 06:48
  • @jeroen What are the downfalls to this? Personally, I've never used such combination before, as I would handle the confirmation before I make a POST request to manipulate the data. – Zhi Kai Aug 15 '17 at 06:55
  • 1
    See my comment below the question. And if javascript is disabled, there is no confirmation at all (Opera mini?). – jeroen Aug 15 '17 at 07:23
-1

Use confirm function from javascript

confirm('message');

echo '<td><a href="candidates.php?id=' . $row['candidate_id'] . '" onclick="return confirm('message goes here')">Delete Candidate</a></td>';

https://www.w3schools.com/jsref/met_win_confirm.asp