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

4
  • javascript popup that cancels the action if the user clicks "cancel": onclick="return confirm('Are you sure?'); Commented Aug 15, 2017 at 6: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. Commented Aug 15, 2017 at 6:47
  • Here is the answer to your problem -> stackoverflow.com/questions/18852373/… Commented Aug 15, 2017 at 6:48
  • 1
    You should even be using a form with CSRF token instead of a simple link Commented Aug 15, 2017 at 6:59

2 Answers 2

1

Try this

echo '<td><a href="candidates.php?id=' . $row['candidate_id'] . '" onclick="return confirm('Are you sure...?')">Delete Candidate</a></td>'; 
Sign up to request clarification or add additional context in comments.

3 Comments

You really shouldn't be using a link in combination with javascript for a delete action.
@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.
See my comment below the question. And if javascript is disabled, there is no confirmation at all (Opera mini?).
-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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.