I have the following form validation.
<?php
$error_occured = 0;
$error_name = "";
$error_email = "";
$error_contact = "";
$error_comments = "";
if(isset($_POST["tx_name"])) {
if(($tx_name == "") || (!preg_match("/^[a-zA-Z ]*$/",$tx_name))) {
$error_occured = 1;
$error_name = "Please enter a valid name";
}
if(($tx_email == "") || (!filter_var($tx_email, FILTER_VALIDATE_EMAIL))) {
$error_occured = 1;
$error_email = "Please enter a valid email";
}
if(($tx_contact == "") || !(is_numeric($tx_contact))) {
$error_occured = 1;
$error_contact = "Please enter a valid contact number";
}
if($tx_comments == "") {
$error_occured = 1;
$error_comments = "Please enter your message";
}
}
if(isset($_POST["tx_name"]) && $error_occured = 0) {
echo "<script>alert('Hi!');</script>";
}
?>
The validation works fine and if there is no error, its supposed to do an alert. However, when I submit the form with no error, I do not see the alert message. How do I fix this?