PHP tutorial-Form


Form

Form is an excellent way to allow users to interact with your web application and submit data across the web pages. In the example below, the user fills out his/her name and age in the text boxes. When the Submit button is clicked, these data will be sent from the Form page to the Welcome page.

Example:

<html>
 <head>
 <title>Welcome Form</title>
</head>
<body>
 <form action="welcome.php" method="post">
Please enter your name and age
<table style="color:black; background:green">
<tr>
 <td>Name:</td><td> <input type="text" name="fname" /> </td>
</tr>
<tr>
<td>Age: </td><td><input type="text" name="age" /> </td>
</tr>
</table>
 
<input type="submit" />
 
</form>
</body>
</html>
 
When a user fill out the form and click submit, the data will be sent to welcome.php file:
 
<html>
<body>
 Welcome <?php echo $_POST["fname"]; ?>!<br />
 You are <?php echo $_POST["age"]; ?> years old.
</body>
</html>
 
Note: $_POST is used to get information submitted by post method. Post method will hide information in address bar and it does not limit the length of information that is attached to the address. $_GET is used to get information submitted by get method. Get method will display information attached with the address in address bar. It limits to the short length of information (100 characters). Alternatively, you can use $_REQUEST to get information from users.



Comments





This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.