English
German

PHP POST and GET

PHP POST and GET

Recall from the PHP Forms Lesson where we used an HTML form and sent it to a PHP web page for processing. In that lesson we opted to use the the post method for submitting, but we could have also chosen the get method. This lesson will review both transferring methods.


POST Review

In our PHP Forms Lesson we used the post method. This is what the pertinent line of HTML code looked like:

Example:

$quantity = $_POST['quantity'];
$item = $_POST['item'];
 

The form names are used as the keys in the associative array, so be sure that you never have two input items in your HTML form that have the same name. If you do, then you might see some problems arise.


PHP GET

As we mentioned before, the alternative to the post method is get. If we were to change our HTML form to the get method, it would look like this:

Example:

$quantity = $_GET['quantity'];
$item = $_GET['item'];
 

After changing the array name the script will function properly. Using the get method displays the variable information to your visitor, so be sure you are not sending password information or other sensitive items with the get method. You would not want your visitors seeing something they are not supposed to!


Security Precautions

Whenever you are taking user input and using you need to be sure that the input is safe. If you are going to insert the data into a MySQL database, then you should be sure you have thought about preventing MySQL Injection. If you are going to make a user's input available to the public, then you should think about PHP htmlentities.


PHP Tutorial,PHP POST and GET, PHP POST and GET example, learn PHP POST and GET,explain example PHP POST and GET online free training PHP Tutorial, PHP Tutorial example, learn PHP POST and GET, online tutorial, download tutorial, PHP Tutorial books, PHP Tutorial videos, live videos PHP Tutorial, learn PHP Tutorial, PHP Tutorial topic PHP POST and GET, live training PHP Tutorial, download free tutorial