A Beginner's Guide to Php [Tutorial 3]

Discussion in 'Web Programming' started by beast217, Jul 22, 2009.

A Beginner's Guide to Php [Tutorial 3]
  1. Unread #1 - Jul 22, 2009 at 10:51 AM
  2. beast217
    Joined:
    Jul 22, 2009
    Posts:
    9
    Referrals:
    0
    Sythe Gold:
    0

    beast217 Newcomer

    A Beginner's Guide to Php [Tutorial 3]

    Hello again :).

    Today we are going to be moving onto something a little bit more advanced, although its still pretty simple in terms of what you are going to be doing in the future tutorials. Today we are gonna make use of what we have learnt of the past 2 tutorials( echo's and variables ) and learn a nifty, vital lesson in php. We will be learning how to transfer information from one page to another.


    Some knowledge of html is required in this lesson. Have a look at the code below:

    Code:
    <html>
    	<head>
    		<title>Tutorial 3</title>
    	</head>
    	<body>
    		<form action = 'page2.php' method = 'POST'>
    			<input type = "text" name = "yourName">
    			<input type = "submit" value = "Go to Page 2">
    		</form>
    	</body>
    </html>
    
    This is a pretty simple script, and as i said earlier, i wont be focusing on teaching you html in these tutorial's. GOOGLE IS YOUR FRIEND.

    Why dont you copy and paste the code above into a text editor and save it as index.php in your tutorial 3 folder ( C:/wamp/www/tutorial 3/). Navigate to localhost and click on tutorial 3. Compare the script to how it looks on the page and see if you can figure out what some of the stuff in the code means.

    Done? Ok.

    notice "method = "POST" ". There are 2 main types of methods to transfer information from one page to another using php, and these are "POST" and "GET". The main difference between the two is that when using GET, you will see extra information in the url bar such as "http://www.yoursite.com/page2.php?name=blabla" instead of "http://www.yoursite.com/page2.php".

    So now that we have created our index.php, lets create our page2.php. Create a new doc in your text editor and save it as page2.php, then paste the code below:

    Code:
    <html>
    	<head>
    		<title>Day 3</title>
    	</head>
    	<body>
    		<?php
    			[COLOR="Lime"]$name = $_POST['yourName'];[/COLOR]
    			[COLOR="MediumTurquoise"]echo 'Hello ' . $name;[/COLOR]
    		?>
    	</body>
    </html>
    
    The text in green:

    $name - a variable called name.
    $_POST['yourName'] - Receiving the text input named yourName via the POST method.


    The Text in tourqiouse:

    echo - If you dont know what this is, please go back to tutorial 1.
    . - this is used as the 'and' in php.
    $name - using the variable in the echo.


    Save it all up. If you get this , then you have done well. Try editing the information such as the page names etc, and see if it still works. Remember, if you ever get errors, just google it.

    Cya at tutorial 4 :).
     
< Flash Intro's | A Beginner's Guide to Php [Tutorial 2] >

Users viewing this thread
1 guest


 
 
Adblock breaks this site