未定义变量:第81行中的date


Undefined variable: date on Line 81

我在PHP文件中再次遇到未定义变量错误的麻烦。错误(日期)发生在PHP文件的第81行,我不确定为什么这个错误不会消失。这个程序应该允许用户以111.222.3.44和mm/dd/yyyy格式输入IP地址和当前日期。有人能指出这里的问题吗?

<html>
<head>
<title>Displaying Errors</title>
</head>
<body>

<?php
    $IP = '/^'d{3}'.'d{3}'.'d'.'d{2}$/';
    $number = '/^([0-9]{2})'/([0-9]{2})'/([0-9]{4})$/';
    if (isset($_POST["IP"])) {$IP = $_POST["IP"];}
    if (isset($_POST["date"])) {$date = $_POST["date"];}
if (preg_match('/^'d{3}'.'d{3}'.'d'.'d{2}$/' , $IP)) 
    { 
        print "Your IP address is good."; 
            if (preg_match('/^'d{2}'/'d{2}'/'d{4}$/', $date))
                { 
                    print "The date format is ok. Thank you for submitting your form<br>."; 
                }
            else if ($date = " ")
    { 
?>
        <form method="GET" method="Lab 10.php" >
        <h1></h1>
        <p>
        IP Address
        <input type="text" name="ip" value="<?php echo $_REQUEST['IP']; ?>"/><br />
        <p style="color:red;">Enter the date mm/dd/yy</p>
        <input type="text" name="date" value="
        <?php echo $_REQUEST['date']; ?>" /><br />

        <br /><br />
        <input type="submit" value="Submit" />
        </form>
        <?php 
        print "<font color='"red'">The date is empty<br></font>";
        print "<font color='"red'">You need to resubmit the form</font>";

    }
    else
    {

        ?><form method="GET" method="Lab 10.php" >
        <h1></h1>
        <p>
        IP Address
        <input type="text" name="IP" value="<?php echo $_REQUEST['IP']; ?>"/><br />
        <p style="color:red;">Enter the date mm/dd/yy</p>
         <input type="text" name="date" value="<?php echo $_REQUEST['date']; ?>" /><br />

        <br /><br />
        <input type="submit" value="Submit" />
        </form>
        <?php
        print "<font color='"red'">The date format is incorrect<br></font>";
        print "<font color='"red'">You need to resubmit the form</font>";
    }
}
else if ($IP = " ") //test if ip address is null
{
    print "<font color ='"red'">The IP Address is empty.</font><br>";


    if (preg_match('/^'d{2}'/'d{2}'/'d{4}$/', $date))
        { 
            print "The date format is ok. Thank you for submitting your form<br>."; 
        }
           else if ($date = " ")
        { 

        ?><form method="GET" method="Lab 10.php" >
        <h1></h1>
        <p>
        IP Address
        <input type="text" name="ip" value="<?php echo $_REQUEST['IP']; ?>"/><br />
        <p style="color:red;">Enter the date mm/dd/yy</p>
        <input type="text" name="date" value="<?php echo $_REQUEST['date']; ?>" /><br />

        <br /><br />
        <input type="submit" value="Submit" />
        </form>
        <?php 
        print "<font color='"red'">The date is empty<br></font>";
        print "<font color='"red'">You need to resubmit the form</font>";

        }
    else
        {

        ?><form method="GET" method="Lab 10.php" >
        <h1></h1>
        <p>
        IP Address
        <input type="text" name="ip" value="<?php echo $_REQUEST['IP']; ?>"/><br />
        <p style="color:red;">Enter the date mm/dd/yy</p>
        <input type="text" name="date" value="<?php echo $_REQUEST['date']; ?>" /><br />

        <br /><br />
        <input type="submit" value="Submit" />
        </form>
        <?php
        print "<font color='"red'">The date format is incorrect<br></font>";
        print "<font color='"red'">You need to resubmit the form</font>";
        }
}

    else //if IP is anything else but accepted
{ 
    print "<font color='"red'">Please enter a valid IP address.</font><br>"; 

    if (preg_match('/^'d{2}'/'d{2}'/'d{4}$/', $date))
        { 
        print "The date format is ok. Thank you for submitting your form<br>."; 

        }

            else if ($date = " ")
        { 
        print "The date is empty<br>";
        print "You need to resubmit the form<br>";
        ?><form method="GET" method="Lab 10.php" >
        <h1></h1>
        <p>
        IP Address
        <input type="text" name="ip" value="<?php echo $_REQUEST['IP']; ?>"/><br />
        <p style="color:red;">Enter the date mm/dd/yy</p>
        <input type="text" name="date" value="<?php echo $_REQUEST['date']; ?>" /><br />

        <br /><br />
         <input type="submit" value="Submit" />
        </form>
        <?php 
        print "<font color='"red'">The date is empty<br></font>";
        print "<font color='"red'">You need to resubmit the form</font>";


        }
    else
        {
        print "The date format is incorrect<br>";
        print "You need to resubmit the form<br>";
        ?><form method="GET" method="Lab 10.php" >
        <h1></h1>
        <p>
        IP Address
         <input type="text" name="ip" value="<?php echo $_REQUEST['IP']; ?>"/><br />
        <p style="color:red;">Enter the date mm/dd/yy</p>
        <input type="text" name="date" value="<?php echo $_REQUEST['date']; ?>" /><br />

        <br /><br />
        <input type="submit" value="Submit" />
        </form>
        <?php
print "<font color='"red'">The date format is incorrect<br></font>";
        print "<font color='"red'">You need to resubmit the form</font>";
        }
}



?>

Simple:

if (isset($_POST["date"])) {$date = $_POST["date"];}

你只设置$date,如果它在$_POST数组中,但你的表单方法是GET