How can PHP header function be utilized to redirect users based on the result of a database action triggered by a button click?
When a button is clicked, a database action is triggered, and based on the result of this action, we can use the PHP header function to redirect users to different pages. By checking the result of the database action, we can conditionally set the location header to redirect users accordingly.
// Perform database action here
// Check the result of the action
if ($result) {
header("Location: success.php");
exit();
} else {
header("Location: error.php");
exit();
}
Related Questions
- How can PHP developers handle varying data lengths within an array for different categories or groups?
- What is the purpose of using __get() in a PHP class for variable access in views?
- How can the use of the glob function simplify the process of working with image files in PHP, as suggested in the forum thread?