In: Computer Science
Using PHP, create a form that uses the method GET.
The form should capture a date using two numbers
Month (1 - 12) and Day (1 - 31)
Make sure the form is filled with the user's input after the form is submitted and processed, and the page is redisplayed.
If data is being passed into the page, then the page should display the date entered by the user and the season of the year. For example, if the user entered 10/12 (October 12), then the results would show something like this:
The date 10/12 is in Fall.
Use these date ranges to determine the season
Spring: March 21 - June 20
Summer: June 21 - September 21
Fall: September 22 - December 20
Winter: December 21 - March 20
PHP CODE
<?php if (isset($_GET["Date"])){
$Date=$_GET["Date"];
$Month=$_GET["month"];
$a=array('January', 'February', 'March');
$b=array('April', 'May', 'June');
$c=array('July', 'August', 'September');
$season="";
if (in_array($Month, $a)){
$season = 'winter';
}
else if(in_array($Month, $b))
{
$season = 'spring';
}
else if(in_array($Month, $c))
{
$season = 'summer';
}
else{
$season = 'Fall';
}
if (($Month == 'March') && ($Date >= 21)){
$season = 'spring';
}
else if (($Month == 'June') && ($Date > 20)){
$season = 'summer';
}
else if (($Month == 'September') && ($Date > 21)){
$season = 'Fall';
}
else if (($Month == 'December') && ($Date > 20)){
$season = 'winter';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible"
content="IE=edge">
<title>GET</title>
</head>
<body>
<h1>DATE</h1>
<form action="<?php $_PHP_SELF ?>"
method="GET">
<h2>Date</h2>
<input type="text"
value="<?php if(isset($Date)){ echo $Date;} ?>"name="Date"
required>
<h2>Date</h2>
<input type="text"
value="<?php if(isset($Month)){ echo $Month;} ?>"
name="month" required>
<input type="submit">
</form>
<?php
if(isset($season)){
echo "Season is: ".$season ;
}
?>
</body>
</html>
------------------------
output
--------------------------
IF YOU HAVE ANY QUERY PLEASE COMMENT DOWN BELOW.
PLEASE GIVE A THUMBS UP