stuffradio
October 17th, 2006, 23:51
Hey, this is the first tutorial I've made... so what do you think?
--------------------------------------------------------------------------------
Part 1:Intro to the tutorials
Hello reader,
I'm assuming you're reading this because you have seen a vast growth on the World Wide Web in the development of Dynamic Websites. These websites could be used to house Forums, CMS's(Content management Systems). By the end of these tutorials you should be able to make your own mini CMS, or be able to modify the vast majority of scripts out there. Since I can't guarantee that everyone uses the same method of making their website as I do, you'll have to read up on the docs they provide... or just study the code yourself.
One requirement for learning PHP is knowing HTML. If you don't know HTML you can go to http://www.htmlgoodies.com/. You'll need HTML to do things like, write your own Forms, Tables for layouts or Div whichever one you prefer to use. Javascript is also a plus for some websites.
I started my website creating career with HTML. The way I learned HTML was by looking at HTML code, erasing some of it, also retyping it in a separate document, saving the file at arbitrary times and seeing what the results looked like. Then I memorized all the commands, few years later I was thinking to myself..., “man, I should learn PHP so I can write my own websites and make CMS's, etc.” I got on the net, kept at it reading tutorial after tutorial. Here I am today teaching others how to write in PHP.
Enough talking, lets begin the first lesson!
Lesson 1: Variables
In PHP, there is a method of storing information where you can access things you stored in any page you write on the website. There are different types of variables. Some are the following:
Static Variables: $variable = “This is a static variable”;
Dynamic Variable: $variable = $statement[table_row];
Global variable: global $variable; $variable = “something”;
Note: In Dynamic Variable you see, $statement[table_row];. That is a method of getting information from a mysql database. You'll learn how to connect and access the database/modify it later on.
OK, you've read all this information, and now want to get something down and see some results! You're going to need some hosting because in PHP you can't just double click a php file and see the results on the fly. You'll either have to setup Apache/PHP on your windows computer at home, or you will have some remote hosting with FTP. The program I prefer to use for coding all my websites in is:
Notepad/Wordpad. I prefer Wordpad because I like the way the text looks, but there really is no difference between the two. In Wordpad when you save the .html or .php files you need to put a quote in front and after your filename otherwise it'll add a .txt to the end of your file. In notepad you shouldn't don't have this problem.
Here is the first script of the tutorials!
Index.html:
<HTML><Title>My First Script!</Title>
<body>
<form action=”calculate.php” method=”post”>
<table cellpadding=”0” cellspacing=”0” border=”0”>
<tr>
<td>Math variable a:</td><td><input type=”text” name=”a”></td>
</tr>
<tr>
<td>Math variable b</td><td><input type=”text” name=”b”></td>
</tr>
<tr>
<td colspan="2"><input type=submit value=Calculate></td>
</tr>
</form>
</table>
</body>
</HTML>
Ok... so in this one script you'll notice a bunch of things. You can see that we've created a form inside of a table. We made a column with Math variable a, and math variable b. The input boxes both have names, which is how we get the data on the second page. The name of the input boxes are just like making variables in php, except it's in HTML, and it's kinda dynamic because it can be anything! So what you need to do now, is make a second script called:
calculate.php
<?php
$a = $_POST['a'];
$b = $_POST['b'];
$math = $a + $b;
echo $math;
?>
That's it! Now you have a script that lets you enter any two numbers in to the input boxes on the html page... have it submit a form to the php page, and you retrieve the information, add them together and echo the output.
You can find what it should look like at:
http://www.wuensche.ca/tutorials/Mathcalc/index.html
http://www.wuensche.ca/tutorials/Mathcalc/calculate.php
Exercise:
Write a form that asks for your details, then have it echo the information on the other page you have the form submit to.
All questions should be emailed to carl@wuensche.ca
Copyright ©2006 StuffTutorials Original owner/writer: Carl Wuensche
--------------------------------------------------------------------------------
Part 1:Intro to the tutorials
Hello reader,
I'm assuming you're reading this because you have seen a vast growth on the World Wide Web in the development of Dynamic Websites. These websites could be used to house Forums, CMS's(Content management Systems). By the end of these tutorials you should be able to make your own mini CMS, or be able to modify the vast majority of scripts out there. Since I can't guarantee that everyone uses the same method of making their website as I do, you'll have to read up on the docs they provide... or just study the code yourself.
One requirement for learning PHP is knowing HTML. If you don't know HTML you can go to http://www.htmlgoodies.com/. You'll need HTML to do things like, write your own Forms, Tables for layouts or Div whichever one you prefer to use. Javascript is also a plus for some websites.
I started my website creating career with HTML. The way I learned HTML was by looking at HTML code, erasing some of it, also retyping it in a separate document, saving the file at arbitrary times and seeing what the results looked like. Then I memorized all the commands, few years later I was thinking to myself..., “man, I should learn PHP so I can write my own websites and make CMS's, etc.” I got on the net, kept at it reading tutorial after tutorial. Here I am today teaching others how to write in PHP.
Enough talking, lets begin the first lesson!
Lesson 1: Variables
In PHP, there is a method of storing information where you can access things you stored in any page you write on the website. There are different types of variables. Some are the following:
Static Variables: $variable = “This is a static variable”;
Dynamic Variable: $variable = $statement[table_row];
Global variable: global $variable; $variable = “something”;
Note: In Dynamic Variable you see, $statement[table_row];. That is a method of getting information from a mysql database. You'll learn how to connect and access the database/modify it later on.
OK, you've read all this information, and now want to get something down and see some results! You're going to need some hosting because in PHP you can't just double click a php file and see the results on the fly. You'll either have to setup Apache/PHP on your windows computer at home, or you will have some remote hosting with FTP. The program I prefer to use for coding all my websites in is:
Notepad/Wordpad. I prefer Wordpad because I like the way the text looks, but there really is no difference between the two. In Wordpad when you save the .html or .php files you need to put a quote in front and after your filename otherwise it'll add a .txt to the end of your file. In notepad you shouldn't don't have this problem.
Here is the first script of the tutorials!
Index.html:
<HTML><Title>My First Script!</Title>
<body>
<form action=”calculate.php” method=”post”>
<table cellpadding=”0” cellspacing=”0” border=”0”>
<tr>
<td>Math variable a:</td><td><input type=”text” name=”a”></td>
</tr>
<tr>
<td>Math variable b</td><td><input type=”text” name=”b”></td>
</tr>
<tr>
<td colspan="2"><input type=submit value=Calculate></td>
</tr>
</form>
</table>
</body>
</HTML>
Ok... so in this one script you'll notice a bunch of things. You can see that we've created a form inside of a table. We made a column with Math variable a, and math variable b. The input boxes both have names, which is how we get the data on the second page. The name of the input boxes are just like making variables in php, except it's in HTML, and it's kinda dynamic because it can be anything! So what you need to do now, is make a second script called:
calculate.php
<?php
$a = $_POST['a'];
$b = $_POST['b'];
$math = $a + $b;
echo $math;
?>
That's it! Now you have a script that lets you enter any two numbers in to the input boxes on the html page... have it submit a form to the php page, and you retrieve the information, add them together and echo the output.
You can find what it should look like at:
http://www.wuensche.ca/tutorials/Mathcalc/index.html
http://www.wuensche.ca/tutorials/Mathcalc/calculate.php
Exercise:
Write a form that asks for your details, then have it echo the information on the other page you have the form submit to.
All questions should be emailed to carl@wuensche.ca
Copyright ©2006 StuffTutorials Original owner/writer: Carl Wuensche