What steps can be taken to effectively debug PHP code when encountering issues with form submissions and redirects?

Issue: When encountering issues with form submissions and redirects in PHP, it is important to check the form action URL, ensure that the form method is set to POST, and verify that the redirect location is correct.

// Check if form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){
    // Process form data
    $name = $_POST["name"];
    $email = $_POST["email"];
    
    // Validate form data
    if(!empty($name) && !empty($email)){
        // Redirect to success page
        header("Location: success.php");
        exit();
    } else {
        // Redirect to error page
        header("Location: error.php");
        exit();
    }
}