Home >>PHP Tutorial >PHP Form
PHP form is used to take input from users. in PHP if you want to take input from keyboard and display the output according to input, in that case you have to use html form. html form's have a property : form method in which you have to set either get or post method. To illustrate, consider the following Web form(choose.php) which asks you to select a brand of automobile and enter your desired color.
Save it as Choose.php
<html> <head> <title>form method</title> </head> <body> <form method="post"> <h2>Select Your car</h2> <table border="1" align="center"> <tr> <td>Select Your car</td> <td> <Selct name="selType"> <option value="porsche 911">Porsche 911</option> <option value="Volkswagen Beetle">Volkswagen Beetle</option> <option value="Ford Taurus">Ford Taurus</option> </select> </td> </tr> <tr> <td>Color:</td> <td><input type="text" name="txtColor"/> </td> </tr> <tr> <td><input type="submit"/> </td> </tr> </table"> </form> </body> </html>
<?php error_reporting(1); $type=$_POST['selType']; $color=$_POST['txtColor']; echo "<font color='blue'>Your $color $type is ready. safe driving! </font>"; ?>
In the given above example: First create a static page using HTML . Form first part is a drop down box from where user has to select the option, 2nd part is a text box in which user enter the color , after entered the value user click on button to display the output. output displays lik Your blue Porshe 911 is ready. safe driving!