0

I have the following code setup to delete records from my database. It executes fine except for the javascript confirm message which never pops up. It just gets ignored completely and the record gets deleted. Any ideas why?

 connect_to_db();
    $query="SELECT id, date, title, image FROM content ORDER BY date DESC";
    $result=mysql_query($query);
    $message= "Continue?";
    while($row = mysql_fetch_array($result)){
    echo '<div id="delete" align="center">';
    echo '<a href="delete.php?id='.$row['id'].'" onclick = "if (! confirm('.$message.')) { return false; }" ><img src="'.$row['image'].'" style="border:1px solid black; width:100px;"><br>Delete</a>';
    echo '</div>';
}
2
  • can you post the anchor html it is outputting? Commented Apr 20, 2012 at 13:45
  • looks to me there is going to be conflicts with 'message' confirm(\''.$message.'\')) Commented Apr 20, 2012 at 13:47

2 Answers 2

2

Your Continue? message is shown as a bare string in the JavaScript code, which is for obvious reasons invalid.

Try this:

'... onclick="return confirm(&quot;'.$message.'&quot;);" ...'
Sign up to request clarification or add additional context in comments.

Comments

1

Looks like a missing quotes issue:

echo '<a href="delete.php?id='.$row['id'].'" onclick = "if (! confirm(\''.$message.'\')) { return false; }" ><img src="'.$row['image'].'" style="border:1px solid black; width:100px;"><br>Delete</a>';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.