- Home
- Registration
- Database Design
- Password Keeper
- MySQL and Excel
- Learn MySQL
- Learn SQL
- Learn C++
- Learn Java
- Learn Visual Basic
- Web Site Tips
- Miscellaneous
- Affordable Hosting
- PHP Code Examples
- Learn PHP
- Virtual Server
- Apache:OS 10048
- PHP Class Example
- Page View Counter
- Display Any Table
- Read csv file
- PHP Array Functions
- Array of Fields
- PHP and MS Access
- Authentication
- PHP App Example
- Display Image PHP
- Image Collection
- Block Spam Post
- Upload File PHP
- $_REQUEST,$_SESSION
- Site map
- Advertise here
- LaptopForLess
- Geeks´ Stuff
- Nerds´ Stuff
- Remote Control Toys
PART I:How to use $_GET and $_POST methods
![]()
![]()
![]()
![]()
![]()
In this tutorial you will learn how to use request variables $_GET, $_POST, $_COOKIE, $_REQUEST and how to use session in PHP
You can use different ways to transfer data from one web page to another. Let us start with Form methods: GET and POST. First we will use GET method Create a simple HTML form.
$_GET[]
<html>
<head>
<title>Form Methods
</title>
</head>
<body>
<form method="get" action="formoutputpage.php">
<p><input type=text name=greeting size="15"></p>
<p><input type=text name=name size="15"></p>
<p><input type=submit name=submit value="Salutation"></p>
</form>
</body>
</html>
Save it as form_methods.php file in your Apache htdocs/post folder created by you.
Let us create a formoutputpage.php file for output data transferred from the form.
<?
echo $_GET['greeting'];
echo $_GET['name'];
echo "!";
?>
Save this file in the same directory as form_methods.php file.
This form looks looks that:
Let us enter a greeting and a name and click Salutation button.
You can see that data sent from a form with the GET method is displayed in browser's address bar:
http://localhost/post/formoutputpage.php?greeting=Hello&name=Emily&submit=Salutation
Output web page displays Hello Emily!
$_POST[]
Let us change POST method instead of GET method. Edit form_method.php form.
<html>
<head>
<title>Form Methods
</title>
</head>
<body>
<form method="post" action="formoutputpage.php">
<p><input type=text name=greeting size="15"></p>
<p><input type=text name=name size="15"></p>
<p><input type=submit name=submit value="Salutation"></p>
</form>
</body>
</html>
Edit formoutputpage.php file as follow:
<?
echo $_POST['greeting'];
echo " ".$_POST['name'];
echo "!";
?>
The browser address bar display formoutputpage.php, but no data transferred with POST Method is visible. Web page output will be the same:
Hello Emily!
Did you find information useful? Send to your friend a link to this page
Please rate the tutorial
| Comments |
|---|
Web programming Tips