In order for this to work with the method you're presently using, you would need to have your HTML on top of PHP.
I tested this with both exit('<div class="alert">Passwords do not match!</div>');
and die('<div class="alert">Passwords do not match!</div>');
<!DOCTYPE html>
<head>
<style>
.alert {
background: #fff6bf url(../images/exclamation.png) center no-repeat;
background-position: 15px 50%;
text-align: center;
padding: 5px 20px 5px 45px;
border-top: 2px solid #ffd324;
border-bottom: 2px solid #ffd324;
}
</style>
</head>
<?php
$pass1="2"; // my own test variable
$pass2="3"; // my own test variable
if($pass1 != $pass2){
exit('<div class="alert">Passwords do not match!</div>');
// die('<div class="alert">Passwords do not match!</div>');
echo "Hello there"; // Will not echo
}
?>
You could do it this way, using an additional conditional statement, instead of killing the script:
<?php
$pass1="2"; // my own test variable
$pass2="3"; // my own test variable
$var = "<div class=\"alert\">Passwords do not match!</div>";
if($pass1 != $pass2){
echo $var;
}
else{
echo "You have access.";
}
?>
<!DOCTYPE html>
<head>
<style>
.alert {
font-family:Georgia;
color:#ffff00;
background: #fff6bf url(../images/exclamation.png) center no-repeat;
background-position: 15px 50%;
text-align: center;
padding: 5px 20px 5px 45px;
border-top: 2px solid #ffd324;
border-bottom: 2px solid #ffd324;
}
</style>
</head>