+ Reply to Thread
Results 1 to 4 of 4

Thread: Beginners Guide To PHP: *Tutorial*

  1. #1
    renlok is offline Newbie
    Join Date
    Dec 2006
    Posts
    1
    Rep Power
    0

    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 07:44 AM. Reason: Link Removed

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Aug 2006
    Posts
    11,209
    Blog Entries
    6
    Rep Power
    101
    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 05:43 AM.

  4. #3
    Jordan Guest
    No, I have not made that script yet but will shortly.

    EDIT: Tutorial looks great!
    Last edited by Jordan; 12-02-2006 at 07:53 AM.

  5. #4
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,174
    Blog Entries
    13
    Rep Power
    114

    Re: Beginners Guide To PHP: *Tutorial*

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

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Basic Compiler Design Tutorial for Beginners
    By Bibek Dahal in forum General Programming
    Replies: 2
    Last Post: 10-17-2011, 01:17 AM
  2. Guide me.
    By cotjones in forum General Programming
    Replies: 5
    Last Post: 11-13-2010, 08:23 PM
  3. Unix : A Beginners Guide
    By imported_Affix in forum Linux Tutorials, Guides and Tips
    Replies: 4
    Last Post: 11-25-2009, 11:52 AM
  4. Replies: 5
    Last Post: 06-16-2009, 09:40 AM
  5. Need Help finding Beginners guide/tutorial
    By RobertQQ in forum C# Programming
    Replies: 8
    Last Post: 07-05-2008, 12:28 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts