PART I:How to use $_GET and $_POST methods
![]()
![]()
![]()
![]()
![]()
By Sergey Skudaev
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!
Please rate the tutorial
Learn SQL Programming By Examples [Kindle Edition]2.99
Learn PHP Programming by Examples [Kindle Edition] $2.99
Learn Visual Basic 6.0 [Kindle Edition] $1.99
How to Build Your Own Web Site from Scratch [Kindle Edition] $1.49
New-trip.com website source code
| Comments | |
|---|---|
- Home
- get_post_cookie_session
- Batch Files
- Environment Variables
- Delete Trojan horse
- Java Properties
- Form Validation
- Display Image PHP
- Upload File PHP
- phpMyAdmin
- Domain Name
- Name Servers
- CPanel: Mail
- CPanel: MySQL
- CPanel: File Manager
- User_Auth. Demo
- Affordable Hosting
- Hosting Expenses
- Modeless Popup
- Virtual Server
- Read Screen Resolution
- 301 Redirect
- PHP + Oracle 1
- PHP + Oracle 2
- Hosting Tips
- Monitor Site
- Create Gallery
- Authentication Script
- Display from file
- CSS Fixed Layout
- CSS Float Layout
- CSS Tables
- Loading Speed
- Set Shopping Cart
- My Best CSS Layout
- Using Twitter
- SEO tips
- Database Design
- Password Keeper
- MySQL and Excel
- Learn MySQL
- Learn SQL
- Learn PHP
- Learn C++
- Learn Java
- Learn Visual Basic
- Site map
- Registration
Web programming Tips