Search code examples
phpanchorhrefconfirmation

Confirm("Message") does not appear when putting in <?php ?>


The onclick='return confirm('Delete this comment?')' seems to be not working at all:

<?php           
     if($sesType == 'Admin') {
        echo "<a href = 'editCom.php?id=$commentID'>Edit</a> ";
        echo "<a href='deleteCom.php?id=$commentID' onclick='return confirm('Delete this comment?')'>Delete</a>";
    } else if($_SESSION["username"] != NULL AND $_SESSION["username"] == $postname) {
        echo "<a href = 'editCom.php?id=$commentID'>Edit</a>  ";
        echo "<a href='deleteCom.php?id=$commentID' onclick='return confirm('Delete this comment?')'>Delete</a>";
    }
?>

But the confirmation box does not appear.


Solution

  • You're using single quotes inside of single quotes. Use double quotes to wrap your code instead:

    <a href='#' onclick="return confirm('Confirmation Message')">Link</a>