Topic: “PHP Control Structures”
project ‘A’: Registration Form
TASK#1:
• In this project we will practice submitting form data to a web site, and returning a response to the user.
• We will also, verify that the user has entered data into the user name field on the form.
® First, you need a Form.
Create the HTML form seen below:
blob.png
NOTE: Use PHP to retrieve and display the current date on the page.
echo "Date: " . date('F dS, Y'); ?>
Remember to save this page with a .php extension!
Save your HTML form page as registerForm.php, upload it to the server and test it in your browser.
TASK#1:
• Next, you need to create the reply.php script which simply captures the values submitted via the form and:
• First, checks to see if the user name field is empty.
o If the user left this field blank, print the following message:
“You did not enter a user name.”
“Please return to the form and re-enter your information.”
o Otherwise, print the message:
“Thank you {print form value of username here!}.”
“You live in lovely region of: {print form value of region here!}.”
Output (Sample screen capture) IF FORM NOT EMPTY
blob.png
Note: “Using the empty() function”
if (empty($variable))
{
print “message here”;
}
else
{
print “ ”;
}
?>
Save your SCRIPT as reply.php, upload it to the web server, and test.