0

This is my first time trying to code php and html together. I've checked every line and still cant figure out why its throwing out an error.

<?php

session_start();

unset($_SESSION['isCompleted']);
$isValid = true;


$fullName = "";
$age = "";
$gender = "";
$errorOne = false;
$errorTwo = false;
$errorThree = false;

// checks to see if user has entered a fullname, else throws an error
if (isset($_POST) && !empty($_POST)){
    if (isset($_POST['fullName']) && !empty($_POST['fullName']))    { 
        $fullName = $_POST['fullName']; 
    }else if ($_SERVER['REQUEST_METHOD'] == "POST"){    
        $isValid = false;
        $error = "Please fill in your Full Name.";
    } 

// checks to see if user has entered a age, else throws an error
    if (isset($_POST['age']) && !empty($_POST['age']))  { 
        $age = $_POST['age']; 
    }else if ($_SERVER['REQUEST_METHOD'] == "POST"){    
        $isValid = false;
        $errorTwo = "Please fill in your Age."; 
    } 

// checks to see if user has entered a gender, else throws an error

    if (isset($_POST['yourGender']) && !empty($_POST['yourGender']))    { 
        $country = $_POST['yourGender']; 
    }else if ($_SERVER['REQUEST_METHOD'] == "POST"){    
        $isValid = false;
        $errorThree = "Please pick your gender"; 
    }

    if ($isValid){ //this syntax checks to see that the value == true. If it were a string, it would just need to exist.
        header('Location: qp2.php');
    }

?>

<html>
    <head>
        <title> Questions Page 1</title>
    </head>

<body>

    <form method="post" action="qp1.php"> 

        <!--Name --> 
        Full Name: <input type="text" name="fullName"/><br/>
        <?php if($error){echo $errorOne; }?>

        <!-- Email --> 
        Age: <input type="text" name="age"/><br/>   
        <?php if($error){echo $errorTwo; }?>
        <br/>

        <!-- How? Dropdown -->
        How did you hear about us?
        <select name="yourGender">
            <option value=""></option>
            <option value="male">Male</option>
            <option value="female">Female</option>
        </select>
        <?php if($error){echo $errorThree; }?>

        <br/>

        <!-- Submit button --> 
        <input type="submit" value="Next"/>


    </form>

</body>
</html>

When I run this file, I get an error in my last line which is but I can't figure out why its causing an error there. Hopefully someone can help me figure out what is wrong with it.

ryuuman123
  • 59
  • 1
  • 8

0 Answers0