php - post &
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 postmethod for submitting, but we
could have also chosen the get method. This lesson will review
both transferring methods.
HTML Code Excerpt:
<form action="process.php"
method="post">
<select
name="item">
...
<input name="quantity"
type="text" />
Now that you know about associative arrays, the PHP code from
"process.php" should make a litte more sense.
PHP Code Excerpt:
$quantity = $_POST['quantity'];
$item = $_POST['item'];
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:
HTML Code Excerpt:
<form action="process.php"
method="get">
<select
name="item">
...
<input name="quantity"
type="text" />
"?item=##&quantity=##"
The question mark "?" tells the browser that the
following items are variables. Now that we changed the method of sending
information on "order.html", we must change the "process.php"
code to use the "$_GET" associative array.
PHP Code Excerpt:
$quantity = $_GET['quantity'];
$item = $_GET['item'];
Comments
Post a Comment
Thank you for your Comment