The
two most used HTTP methods are: GET and POST. The PHP superglobals $_GET and $_POST are used to collect form-data.
What is HTTP?
The
Hypertext Transfer Protocol (HTTP) is planned to enable interactions between
clients and servers.
HTTP
works as a request-response protocol between a client and server.
A
web browser may be the client, and an application on a computer that hosts a
web site may be the server.
Example:
A client (browser) submits an HTTP request to the server; then the server
returns a response to the client. The response contains status information
about the request and may also contain the requested content.
Two HTTP Request Methods: GET and POST
Two HTTP Request Methods: GET and POST
Two
commonly used methods for a request-response between a client and server are:
GET and POST.
- GET - Requests data from a specified resource
- POST - Submits data to be processed to a specified resource
In GET method associative array of variables passed to the
current script via the URL parameters.
create and index.php file inside your root directory and put the given code.
PHP Code:
- <?php
- $name = $_GET['name'];
- echo "Name is ".$name;
- ?>
Now lets talk about HTTP POST method in php. HTTP POST requests
deliver additional data from the browser to the server in the message body. In
contrast, GET requests
consist of all required data in the URL. Forms in HTML can use either method by
specifyingmethod="POST" or method="GET" (default) in the <form> element.
The method specified determines how form data is submitted to the server. When
the method is GET, all form data is encoded into the URL, appended to the action URL as query string parameters. With
POST, form data appears within the message body of the HTTP request.
First of all make a html form in index.php file that we recently created.
HTML Code:
- <html>
- <head>
- <title>intphp.blogspot.com</title>
- </head>
- <body>
- <form method="post" action="index.php" >
- <table border="1">
- <tr>
- <td>Enter Name :</td><td><input type="text" name="name" ></td>
- </tr>
- <tr>
- <td colspan="2"><input type="submit" name="submit" value="Submit Form"></td>
- </tr>
- </table>
- </form>
- </body>
- </html>
Form will look like the given form:
Enter Name : | |
Now write the php code at anywhere in index.php file:
HTML Code:
- <html>
- <head>
- <title>intphp.blogspot.com</title>
- </head>
- <body>
- <form method="post" action="index.php" >
- <table border="1">
- <tr>
- <td>Enter Name :</td><td><input type="text" name="name" ></td>
- </tr>
- <tr>
- <td colspan="2"><input type="submit" name="submit" value="Submit Form"></td>
- </tr>
- </table>
- </form>
- </body>
- </html>
- <?php
- if(isset($_POST['submit'])){
- $name = $_POST['name'];
- echo "Name is : ".$name;
- }
- ?>
Keyword
if else if in php
php if else
if else if php
if else condition in php
php if else shorthand
php if then else
php implode
php tutorial
php if else if
php script
php for loop
php file upload
learn php online
php cookie
elseif in php
php if else endif
learn php
session php
learning php
php if else statement
learn ruby
php scripts
php tutorial pdf
php form
php for beginners
curl php
how to learn php
php setcookie
substr php
fopen php
php string functions
php mktime
php learning
php strstr
php unset
php for dummies
php case else
php learn
php course
if elseif in php
how to use else if in php
php sample code
php if else syntax
learn php fast
best way to learn php
conditional statement in php
php if elseif else
php lessons
php lesson
learn php programming
php if else in html
php else if example
php conditional statement
php online tutorial
php if else elseif
how to learn php language
php scripting language
tutorial for php
tutorial on php
learning php online
tutorial of php
php study
else if statement in php
php switch syntax
tutorials php
conditional statement php
if syntax php
download php tutorial
how to learn php at home
how to write an if statement
syntax of php
online php learning
php else statement
php complete tutorial
learn php tutorial
how to learn php programming
tutorials for php
study php
php study material
tutorials on php
how learn php
learn php code
learn php 5
how can i learn php
tutorials of php
learn php5
php conditional if
where to learn php
complete php tutorial
easy way to learn php
condition statement in php
if statement tutorial
how to use an if statement
php if statement syntax
case statement in php
how to use if condition in php
php 5 tutorials
learn php video
how to do a if statement
home learn php
to learn php
syntax for if
teach me php
learn php quickly
what is the conditional statement
how to do if functions
parts of conditional statement
Keyword
switch in php
switch case php
switch case in php
switch statement php
case switch php
switch statement in php
php case switch
learn php
learn php online
learning php
switch php default
switch php example
how to use switch case in php
php lesson
switch cases
variable switch
tutorial on php
tutorial for php
tutorial of php
tutorials php
switch variable
php case select
break statement in php
tutorials on php
operator switch
php site search
how learn php
tutorials for php
how to php code
use of switch statement
case statement in php
tutorials of php
learn php tutorial
php 5 tutorials
how can i learn php
php break statement
php tutorial site
to learn php
switch case statement in php
how to use and operator in php
select statement with case