samedi 17 juillet 2021

my if condition is not working inside my switch case, code rather. move directly to the default statement even when the conditions inside if is true

// this is my form that take first name and last name // can someone help me out

    <form action="signup_verification.php" method='POST'>
                <div class="form-box">
                    <label for="first_name">First name:</label>
                    <input type="text" name='first_name'>
                </div>
                <div class="form-box">
                    <label for="last_name">Last name:</label>
                    <input type="text" name='last_name'>
                </div>
    </form>
    

// this is my php code to verify if all conditions are set properly.

    <?php
        $errormsg='';
        foreach ($_POST as $post){
            $post = htmlspecialchars($post);
        }
        switch($post):
            case 'first_name':
                if(empty($_POST['first_name'])){
                    $errormsg='First name is required';
                    return header('location:http://localhost:8888/LoginSite/signup.php?errormsg='.$errormsg);
                    break;
                }
            break;
            case 'last_name':
                if(empty($_POST['last_name'])){
                    $errormsg='Last name is required';
                    return header('location:http://localhost:8888/LoginSite/signup.php?errormsg='.$errormsg);
                    break;
                }
            break;
    
            default: 
                echo'yes';
        endswitch;    
    ?>

Aucun commentaire:

Enregistrer un commentaire