Receiving the information from HTML forms October 1, 2008
Posted by me2blog in Common PHP Applications, php.Tags: check box, difference between GET and POST, GET, php, POST, receive the information from check box, Receive the information from HTML forms
trackback
The forms data r available at PHP built in array. As said earlier there two methods to send the data: POST and GET, so information from any form uses the method POST is available in the built-in array $_POST with the key for each field with it’s name! and information from any form uses the method GET is found in the array $_GET, and the key for each field is it’s name …
The information that user select from drop down menu or radio buttons r similarly available for use, but the situation is a lil different while using check boxes bcz the user can check more than one box, the information is in multidimentional array ,,,, but i think there is an easier wayL when u create check box bottons, name each buton a unique name, and get it from 1D array, it will be faster and easier to code … remember no one can c ur code ,,, every one will c the effect of ur code, so write it in the easiest way 4 u :p
What is the difference between POST and GET:
- Get method: The form data is passed by adding it to the URL. The advantages for this method: it’s simple and fast but the disadvantages r less data to be passed and less secure (since the information r displayed in the browser).
- Post method: The form data is passed as a package in a separate communication with the processing script. The advantages: unlimited information to be passed and more secure and the disadvantage is the overhead which slows the speed.
Example:
<br><center><h2> Customer information </h2></center>
<br><br>
<center>
<table border=”0″>
<form action=”customer_info.php” method=”POST”>
<tr> <td> First name:</td> <td> <input type=”text” name=”first_name” value=”enter ur first name plz”></td></tr>
<tr> <td>Second name: </td> <td> <input type=”text” name=”second_name” value=”enter ur second name plz”> </td></tr>
<tr><td>Last name: </td> <td> <input type=”text” name=”last_name” value=”enter ur last name plz”></td> </tr>
<tr><td> Street Address:</td><td> <input type=”text” name=”st_address” value=”enter ur st address plz”></td> </tr>
<tr><td> City:</td><td>
<select name=”city”
<option> Amman </option>
<option> Aqaba </option>
<option> Irbd </option>
<option> Zarqa </option>
</td> </tr>
<tr><td>Sex: </td><td>
<input type =”radio” name=”Radio1″ value= “M” > Male
<input type =”radio” name=”Radio1″ value= “F”> Female
</td></tr>
<tr><td>Your Operating system: </td><td>
<input type= “checkbox” name=”os0″ value=”W”> Windows
<input type= “checkbox” name=”os1″ value=”L”> Linux
<input type= “checkbox” name=”os2″ value=”M”> Mac
</td></tr>
</table><br>
<input type=”submit” value=”submit name”>
</form>
and now …. the customer_info.php code:
<?php
if ($_POST[Radio1]==”M”) {
$sex= “Male”;
}
else
{
$sex= “Female”;}
echo “Welcome “,$_POST['first_name'],”!<br>”;
echo “Your second name is: “,$_POST['second_name'];
echo “<br>Your last name is: “,$_POST['last_name'];
echo “<br>”;
echo “you are “, $sex;
echo ” living in: “, $_POST[city];
echo “ in the “, $_POST[st_address],” Street”;
echo “<br>and your operating systems are: <br>”;
if (isset($_POST['os0'])) {
echo “Windows<br>”;
}
if (isset($_POST['os1'])) {
echo “Linux<br>”;
}
if (isset($_POST['os2'])) {
echo “Mac<br>”;
}
?>
The output:
and after clicking the submit name button u will c the following page:
Welcome Noor!
Your second name is: A
Your last name is: Adiga
you are Female living in: Aqaba in the Abc ST Street
and your operating systems are:
Windows


Comments»
No comments yet — be the first.