Final Code Challenge
Posted on 12. Mar, 2010 by admin in Basics
Looks like our teaching time is coming to a close. You have gone from not knowing what PHP is to well versed. You must pass one final test before you are a true PHP Master!
Questions
Q: What is the purpose of an HTML form?
Show Answer ▼
HTML forms allow us to submit values to PHP which we can process.
Q: What are the two types of data that a form can send?
Show Answer ▼
Q: What are the two types of data that a form can send?
Show Answer ▼
Q: Which method of sending data sends the data via the URL?
Show Answer ▼
Q: Which method is best for sending secure information like passwords?
Show Answer ▼
The POST method, because if you used the GET method you would see your password in the URL!
Programming Projects
Project One: Write a HTML form and PHP script that takes someones order.
Show Answer ▼
<html>
<head>
<title>Final Code Challenge</title>
</head>
<body>
<form action="index.php" method="post">
What drink do you want?: <input type="text" name="drink" /><br/>
What do you want to eat?: <input type="text" name="eat" /><br/>
What would you like for dessert: <input type="text" name="dessert" /><br/>
<input type="submit" />
</form>
</body>
</html>
<?php
echo "To drink you would like ".$_POST["drink"]."<br/>";
echo "To eat you would like ".$_POST["eat"]."<br/>";
echo "For dessert you would like ".$_POST["dessert"]."<br/>";
?>
Output:
To drink you would like coke
To eat you would like pizza
For dessert you would like cookies
Project Two: Use the GET method to break down the following statement “?one=you&two=have&three=done&four=it”. (Add it to the end of the URL of the page)
Show Answer ▼
<?php
$one = $_GET["one"];
$two = $_GET["two"];
$three = $_GET["three"];
$four = $_GET["four"];
echo $one." ".$two." ".$three." ".$four;
?>
Output:
you have done it
Conclusion
Well that concludes our brief introduction to PHP. There is so much more to learn, so stick around for more. Don’t forget to subscribe on the right of the page. If you have any requests for tutorials or scripts, please let us know in the feedback section of the forum.