0

我的 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>";
        }

}







?>

4

1 回答 1

3

简单的:

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

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

于 2013-03-01T23:51:50.060 回答