Lost Password?


  #1 (permalink)  
Old 12-02-2006, 06:27 AM
renlok renlok is offline
Newbie
 
Join Date: Dec 2006
Posts: 1
Rep Power: 0
renlok is on a distinguished road
Default Beginners Guide To PHP: *Tutorial*

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
Now for the explanation of it all.
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
?>
Name the page2.php it is important to give every page you create containing php the suffix of .php or the web server will ignore all your <?php and ?> tags
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 12-02-2006, 08:38 AM
TcM's Avatar   
TcM TcM is offline
Code Warrior
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 8,332
Rep Power: 68
TcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of light
Default

Well nice I must say! Why don't you post that in this forums Tutorials section?

EDIT:- Jordan didn't you make that script that users with less than 5 post will not be allowed to post links?

Last edited by TcM; 12-02-2006 at 08:43 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 12-02-2006, 10:40 AM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Posts: 9,203
Last Blog:
Ext JS or Ext GWT
Rep Power: 20
Jordan is just really niceJordan is just really niceJordan is just really niceJordan is just really nice
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-22-2008, 04:20 PM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: On God's Planet
Posts: 9,583
Last Blog:
Web slideshow in JavaS...
Rep Power: 76
Xav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud of
Send a message via MSN to Xav
Default Re: Beginners Guide To PHP: *Tutorial*

I've just read the tutorial - and now I'm going to learn PHP.
__________________


Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

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


All times are GMT -5. The time now is 07:22 AM.

Contest Stats

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

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 97%

Ads