Page 1 of 1

create a simple form

Posted: Sun Aug 31, 2014 9:31 am
by loyd.augustine
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

Re: create a simple form

Posted: Sun Aug 31, 2014 1:56 pm
by donny
Form Page

Code: Select all

<form action="process.php" method="post">
Name: <input type="text" name="firstName">
<input type="submit" value="Next">
</form>
process.php

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.