PHP ファイル内の未定義変数エラーで再び問題が発生しています。PHP ファイルの 81 行目でエラー (日付) が発生していますが、このエラーが解消されない理由が正確にはわかりません。このプログラムは、ユーザーが IP アドレスと現在の日付を 111.222.3.44 および mm/dd/yyyy 形式で入力できるようにすることを想定しています。誰かがここで問題を指摘できますか?
<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>";
}
}
?>