Tutorials Navigation
How to Create a simple PHP form
Tutorial Name: How to Create a simple PHP form
Category: PC Tutorials
Submitted By: Mitzz
Date Added:
Comments: 1
Views: 3,992
Related Forum: PC Building Forum
Share:
First we will create a simple HTML form which will contain three input fields:
- Name
- Value 1
- Value 1
We will then handle the data user submitted with PHP:
To create a form you can paste the code bellow into your favorite text editor and save it under name lesson3.php.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Simple PHP form</title>
</head>
<body>
<h2>Simple PHP form</h2>
<form method="get" action="lesson3.php">
Name: <input type="text" name="name" /> <br />
Value 1: <input type="text" name="value1" /> <br />
Value 2: <input type="text" name="value2" /> <br />
<input type="submit" value="Submit" />
</form>
</body>
</html>
When the user will enter the data into input fields and press Submit button, the data will be sent to the page, specified by the action parameter in form from previous step.
In our case we have used name lesson3.php which means that the data will be sent to our document.
Now we must add some PHP code to handle the input data.
Below the form we add the following code:
<?php
if (isset($_GET['name'])) {
$val1=$_GET['value1'];
$val2=$_GET['value2'];
echo "The user submited form ".$_GET['name']. ' <br />';
echo "Values submited are: $val1, $val2";
}
?>
As you can see the data from the user form is available in the $_GET variable under the name of input field.
If we enter the data into the input fields and press Submit button, you should get a result showing the values you entered.
When we specified a form, we defined method="get"
The result is that input values will be appended to URL.
If you want to change this behavior you should change the method to post:
<form method="post" action="lesson3.php">
Ratings
Comments
Related Tutorials
- 01. Emulating Xbox 360 on PC for Running COD4 With Mods(3,493)
- 02. How to: Matrix Numbers | Batch File(1,904)
- 03. How to Password Protect Files on Windows(857)
- 04. How to play Socom 2/3/ and Combined Assault on PC(6,718)
- 05. Modern Warfare 2 Vac Ban Bypass Tutorial(6,134)
- 06. How to embed an image on TheTechGame(3,099)
- 07. [PC] NIOH 2 OTHER USER SAVE RESIGN(12,983)
- 08. Host bot lobbies! Full Tutorial!(11,246)
- 09. Unban yourself [Plutonium BO2](14,241)
- 10. Fall Guys - How to Change Your Name Color on Fall Guys(8,386)
- 11. Best Crosshair Settings for Valorant(6,526)
- 12. Othercide The Surgeon Boss Guide(2,540)
- 13. Othercide Remembrances Unlock Guide(4,461)
- 14. Othercide Beginners Tips and Tricks(2,709)
- 15. How to Fix Grounded Crashes, Loading Time, Low FPS and Other(4,846)
"How to Create a simple PHP form" :: Login/Create an Account :: 1 comment