2013-03-01 2 views
1

PHP 파일에서 정의되지 않은 변수 오류로 다시 한 번 문제가 있습니다. 오류 (날짜)는 PHP 파일의 81 행에서 발생하며이 오류가 가라 앉지 않는 이유를 정확하게 알지 못합니다. 이 프로그램은 사용자가 IP 주소와 현재 날짜를 111.222.3.44 및 mm/dd/yyyy 형식으로 입력 할 수 있도록합니다. 누군가 여기서 문제를 지적 할 수 있을까요?정의되지 않은 변수 : date on Line 81

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

} 







?> 

+5

전체를 덤프하지 마십시오입니다

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

코드를 작성하고 해결해 줄 것을 기대하십시오. 오류를 분리하십시오. 변수를 조작하기 전후에 변수를 인쇄하십시오. – Cfreak

+0

나는 누군가가 내 문제를 간단하게 해결하고 올바른 해결책을 제공 할 것이라고 기대하지 않고 올바른 방향으로 나를 안내했다. stackoverflow에 익숙하지 않기 때문에 사이트를 올바르게 사용하는 방법을 알고 싶지 않습니다 ... – MDSL1806

답변

3

간단한 : 그것은 $_POST 배열의 경우에만 $date을 설정하고 있지만 양식 방법은 GET