| ||
Post & Get
When HTML form send data to the server, PHP can extract the data for processing. PHP - POST In post method HTML code looked this: POST
Code Excert: <form
action="process.php" method="post"> <select name="item"> ... <input name="quantity" type="text" /> This means that the form data will be submitted to the "process.php" web page using the POST method. In
POST method, the data is sent in the body
of the request. PHP stores all the "posted" values in an associative array called "$_POST". The values of "name" of the form became the keys in the "$_POST" associative array. PHP - POST:
$quantity = $_POST['quantity'];
$item = $_POST['item']; As the names in a form are used as the keys in the associative array, make sure that names of input items are unique. If not there will be problems. PHP -
GET The alternative to the post method is get. HTML form using the get method looks like this: GET
Code Excert: <form
action="process.php"
method="get">
<select name="item"> ... <input name="quantity" type="text" /> This means that the form data will be submitted to the "process.php" web page using the GET method. In get
method, the data is sent by appending
them to the end of the URL
The URL, after clicking submit, would have this added on to the end of it: item=book&quantity=2
The question mark "?" tells the browser that the following items are variables. The values of "name" of the form became the keys in the "$_GET" associative array. PHP - GET: $quantity =
$_GET['quantity'];
$item = $_GET['item']; Note |