How can PHP be used to display different HTML pages based on the validation of a form?
To display different HTML pages based on the validation of a form in PHP, you can use conditional statements to check the form input and redirect the user to the appropriate page. After validating the form input, you can use header() function to redirect the user to the desired page.
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Validate form input here
if (/* validation condition */) {
header("Location: success.html");
exit();
} else {
header("Location: error.html");
exit();
}
}
?>
Related Questions
- Are there any potential pitfalls to using regular expressions with preg_match to filter URLs in PHP?
- How can PHP and MySQL be effectively utilized to create a user login system with email verification and data input forms, considering the differences in functionality compared to Access?
- What is the best practice for checking if form values are defined before using them in PHP?