Helo. i am learning php, and i need help creating below for. Its simple but i need help.
Create a form that contains:
1. Name, textbox
2. Submit button
If the user inputs the Name textbox and clicks the Submit button, the system must:
1. Display "Good morning, <Name>" if the server time is within 12am-12 noon
2. Display "Hello, <Name>" if the server time is not within 12am-12 noon
<Name> is the value as inputted by the user into the textbox
create a simple form
Moderator: General Moderators
Re: create a simple form
Form Page
process.php
I am pretty new to PHP so there is probably a better way of doing it, but it works.
Code: Select all
<form action="process.php" method="post">
Name: <input type="text" name="firstName">
<input type="submit" value="Next">
</form>
Code: Select all
<?php
date_default_timezone_set('EST'); //Time Zone
$time = date("H"); //Military Time Hour Only
$firstName = $_POST['firstName'];
$range = range(00,12);
if(in_array($time, $range)){
echo "Good morning, $firstName";
}
else{
echo "Hello, $firstName";
}
?>
I am pretty new to PHP so there is probably a better way of doing it, but it works.