|
||||||
| PHP Tutorials PHP Tutorials |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
i wrote a tutorial wondering if its any good?
-------About PHP------------------------------------------------- Ok so you’ve decided to learn php, first thing you may want to know is what php is capable of doing for you it has many uses, it is used all across this site in fact its mainly the only programming language I have used on WeLink but the main use people would want to learn php would be to integrate your site with a user system of sorts. -------PHP, Very Basics------------------------------------------- Ok here we will get down to the coding parts, most probably if your reading this would be what you want to learn about. To start you off here is a extremely simple program, and here it is: Code:
<?php //opening php tag echo 'This is my page'; //php code telling the web server to treat this is my page as html ?> //closing php tag you see the <?php and ?> these are called PHP tags and tell the web server where the php code starts and finishes. So anything outside this will be considered normal HTML. On line 2 the first piece of code is echo as you can see this tells you web server to treat the following piece of text contained in the inverted commas ' as regular html, so then the 'This is my page' is what is printed the ' must be included unless your wanting to include a variable these will be covered later on. At the end of this line you may of notice the semi colon ; this is very important to be included at the end of every line. Now When you upload this to your browser you should see Quote This is my page I know this isn’t very exiting but stick with it, it gets more interesting i promise. ---------Variables---------------------------------------------------- Variables are a very useful part of php, one use is that you can use them to store information from one page to another. Here is the code for your first page. Code:
Your Name: //text explaining the input box <form name="name" method="post" action="page2.php"> //details of how the form will behave <input type="text" name="yourname"> //details on the input box <input type="submit" name="Submit" value="Submit"> //the button which submits the form </form> //the form ending tags This is a simple form code you would know about this is you've used html. The parts that are relevant to this program are on the first line action="page2.php" this tells the browser where to forward you to once you’ve filled out the forum. On the second line name"yourname" this is important when you get to making your own that you put relevant names here as your going to have to remember it later on. Then name this page1.html Now onto where the magic happens, The second page will have contain the code: Code:
<?php $yourname = $_POST['yourname']; //retrieves data from the input form echo 'Hello '.$yourname; //prints the data ?> You will notice this is not that different from the first piece of php code $yourname this is a variable you can tell from the leading $ you must also give these relevant and remember able names for ease later on during your coding. When you open page1.html and enter say john into the input box this new page will load showing something like Hello John (or what ever you entered before). The $_POST variable is used to 'catch' information from forms that have the input type of submit or post. The ['yourname'] following it tells it which piece of data to catch from the form, you should remember from before what you named your input box as notice that was given the same name as this. This is because its that curtain piece of data your php is waiting to receive. If you have a more complicated form you would have many more of these being used but for now we will only use the one. The entire line of $yourname = $_POST['yourname']; simple tells the browser to set the variable of $yourname to the value of whatever yourname was entered as in the form. In the line bellow the echo command is used again you may also of noticed the full stop . and that $yourname isn’t surrounded by ', the full stop . is there to tell the browser that there’s another piece of information stringed to this line after the '' brackets have closed this is used instead of writing everything out long hand like echo 'Hello'; echo $yourname; as this would become very tedious especially when you come to typing out large pieces of code. Finally $yourname isn’t surrounded by ' simply because you don’t use them around variables. There are other things that don’t need them but we wont go into them now. REMEMBER: * $ followed by text with no spaces means its a variable * Everything you want shown with a echo commend must be surrounded by ' or " unless its a variable * To join pieces of code place a . after each piece and put a ; after every line of code TBC If there are any errors with this tutorial please tell me and I will fix them also if there’s anything you think needs adding or changing. eventually i will make others Last edited by xXHalfSliceXx; 12-02-2006 at 10:44 AM. Reason: Link Removed |
| Sponsored Links |
|
|
|
|||||
|
No, I have not made that script yet but will shortly.
EDIT: Tutorial looks great!
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog The CodeCall Wiki is now fully integrated with vBulletin users! Check it out and add some new pages! Last edited by Jordan; 12-02-2006 at 10:53 AM. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| PHP 4 end of life announcement | Jordan | Programming News | 4 | 08-30-2007 10:55 AM |
| PHP Introduction | clookid | PHP Tutorials | 10 | 01-16-2007 08:17 AM |
| WingedPanther | ........ | 2753.6 |
| Xav | ........ | 2704 |
| Brandon W | ........ | 1702.32 |
| John | ........ | 1207.73 |
| marwex89 | ........ | 1175.24 |
| morefood2001 | ........ | 966.05 |
| dcs | ........ | 655.75 |
| Steve.L | ........ | 475.59 |
| orjan | ........ | 418.58 |
| Aereshaa | ........ | 383.54 |
Goal: 100,000 Posts
Complete: 97%