PHP if,else语句。 出生验证的形式和日期

Im writing code practicing PHP if and else statements and form validation.

the basic idea is this: After entering name, DOB , and email and clicking the submit button, Based on the DOB they enter the button leads them to leads to:

-a page telling them they are too young to drink (notwelcome.php)

OR

-a page telling them they can order a drink (welcome.php)

The 2 pages (notwelcome.php & welcome.php) are pulled from separate file called action.php saved like this:

<?php
include('welcome.php');
include('notwelcome.php');
?>

This is what i have been trying ..but its not working. nothing happens.. Its as if the if else code isnt even there :(

<?php

if ($_POST['submit']) {

    $dob = $_POST['dob'];

    if (isset ($_POST['dob'] )> 12/31/1992) {
        header("Location: notwelcome.php");
} else {
        header("Location: welcome.php");}
}
?>

Help. Im a beginner and i have hit a small bump in the road in my code.

additional infor:

HTML Code is like this:

    <div style="text-align: center;">

        <h2>FORM & PHP</h2>

        <h3>WHINE & DINE</h3>
        <form action="action.php" method="post">
           Full Name: <input type="text" name="name"><br>
           Date of Birth: <input type="date" name="dob"><br>
            E-mail: <input type="text" name="email"><br>
            <input type="submit" data-inline="true" value="Submit">

        </form>
        </div>
    </div>
        </form>

Try this. Also, you don't need to include those files unless you want them showing up on the page before you process the form. I would check to make sure you have the relative path correct. You would also want to make it so users enter the DOB in the right format.

<?php

if (isset($_POST['dob'])) {

    $dob = $_POST['dob'];

    if ($dob > date("m/d/Y", mktime(0, 0, 0, date('m'), date('d'), date('Y') - 21))) {
        header("Location: notwelcome.php");
    } else {
        header("Location: welcome.php");}
}
?>

You can try this. In php code you can add additional if conditions to check validity of ranges.

<?php
if (isset($_POST['date']) && isset($_POST['month']) && isset($_POST['year']) ) 
{
    $dob = date_format (date_create ($_POST['year']."-".$_POST['month']."-".$_POST['date']), "Y-m-d");
    if ($dob > date("Y-m-d", mktime(0, 0, 0, date('m'), date('d'), date('Y') - 21)))
      {
        header("Location: notwelcome.php");
      } 
    else 
      {
        header("Location: welcome.php"); 
      }
}
?>

<html>
<head></head>
<body>
<div style="text-align: center;">

        <h2>FORM & PHP</h2>

        <h3>WHINE & DINE</h3>
        <form action="r.php" method="post">
           Full Name: <input type="text" name="name"><br>
           Date of Birth: <select name="month">
<option value="01">January</option><option value="02">February</option><option value="03">March</option>
<option value="04">April</option><option value="05">May</option><option value="06">June</option>
<option value="07">July</option><option value="08">August</option><option value="09">September</option>
<option value="10">October</option><option value="11">November</option><option value="12">December</option></select> <select name="date" >
<option value="1">01</option><option value="2">02</option><option value="3">03</option>
<option value="4">04</option><option value="5">05</option><option value="6">06</option>
<option value="7">07</option><option value="8">08</option><option value="9">09</option>
<option value="10">10</option><option value="11">11</option><option value="12">12</option>
<option value="13">13</option><option value="14">14</option><option value="15">15</option>
<option value="16">16</option><option value="17">17</option><option value="18">18</option>
<option value="19">19</option><option value="20">20</option><option value="21">21</option>
<option value="22">22</option><option value="23">23</option><option value="24">24</option>
<option value="25">25</option><option value="26">26</option><option value="27">27</option>
<option value="28">28</option><option value="29">29</option><option value="30">30</option><option value="31">31</option>
</select> <input name="year" type="text" id="year" size="4" maxlength="4"> <span>(YYYY)</span>
<br>
E-mail: <input type="text" name="email"><br>
<input type="submit" data-inline="true" value="Submit">
</form>
</div>          
</body>     
</html>

There's probably a more elegant way to do it, but this worked for me:

if(isset($_POST['dob'])) { $dob = $_POST['dob'];
    list($date,$time) = explode(" ", $dob);
    list($year,$month,$day) = explode("-",$date);
    $years  = date("Y") - $year;
    $months = date("m") - $month;
    $days   = date("d") - $day;
        if (($years > 21) || ($years == 21 && $months > 0) || ($years == 21 && $months == 0 && $days >= 0)) {
        header("Location: welcome.php");
        } else {
        header("Location: notwelcome.php");
        }
}

Subtracting the birth year from the current year, the birth month from the current month and the birth day from the current day, this basically runs up to three tests. First, if the current year is more than 21 years after the person's birth year, they're legal. Second, if it's 21 years after the person's birth year but it's after their birth month, they're legal. Finally, if it's 21 years after the person's birth year and it happens to be their birth month and the day of the month is greater than or equal to the person's birth day, they're legal. If none of those things are true, they're under 21.