Your First Site : Part 2
Hi There Pretty Brain ...
Please note that this tutorial is part of the Build Your Own Site series of tutorials. Feel free to restart the series.
In this tutorial we'll continue where we left off in the first part of this lesson. We created an html page in part 1 with a form. The form had two inputs , both of which were text input fields. The code looked like this:
<!DOCTYPE HTML>
<html>
<head>
<title>The First Site | Yeaaahhh Boooiiiiiyy!!</title>
</head>
<body>
<form action="/action_page.php" method="get">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Remember this bad boy? - "Alright, alright, alright ..." - Denzel Washington
"first_site.html"
page.
We'll call this one "action_page.php"
, exactly the value of our form's action attribute. Yep you guessed it, because we are sending the form submission request to this file.
Meaning after submission, the server will parse this page the data from the form, and you can handle the processing of the incoming data and do whatever you want after.
Buckle up soldier, it's about to get all kinds of fun all up in here!!!
Insert this code in the "action_page.php"
file:
<?php
echo "we're in here fool!!";
?>
Yeaahh Booiiyy!! - now reload the "http://localhost/first_site.html"
page , fill out the form, submit and voila!! ... The server will load you "action_page.php"
page into the browser. Neat right ...
"Alright, alright, alright ..." - Matthew McConaughey
"action_page.php"
file is PHP. Anything between those php tags is php. The server knows to execute whatever is between them as php.
The statement in between the tags is an echo function, one of php's many core functions. What it does really is simply output a string/text. Hence when "action_page.php"
is loaded we get "we're in here fool!!".
As you might have noticed, like most scripting languages, php requires a closing semi-colon for each statement; that's how it knows the statement is done. Otherwise it will keep reading and try to find this. It might return an error if the semi-colon is not specifically and adequately written in your code.
"In this part of the lesson, we'll be building the page to which the form will be submitting to"
The Village Geek
Don't worry about it Phillip, we'll now start an in depth introduction to php, what it is, and most importantly - how to use it.
"Alright, alright, alright ..." - Matthew McConaughey
Cape Town, South Africa