Basic form and data display using PHP

We will try to learn how a simple web form works and how to collect the data as entered by users. This is a very basic and common requirement so we have included all types of form component in our example. Before reading check this html form basic tutorial

For our tutorial we have used two files one is demo-basic-form.php file which has the html form and other file is demo-basic-form2.php file which has the script to collect the form data and display them.


Name
SexMale |Female |
Languages you knowPHP ASP   JavaScript
Select one day




Here is the code for demo-basic-form.php
<form method=post action='demo-basic-form2.php'>
<input type=hidden name=todo value=submit-form>
<table cellspacing=0 cellpadding=0 width='484' border=0 align=left bgcolor='#f1f1f1'>
<tr><td>Name</td><td><input type=text name=t1 value=''></td></tr>
<tr bgcolor='#ffffff'><td>gender</td><td><input type=radio name=gender value='Male' >Male
|<input type=radio name=gender value='Female' >Female |</td></tr>
<tr><td>Languages you know</td><td><input type=checkbox name=c1 value=yes >PHP 
<input type=checkbox name=c2 value=yes >ASP &nbsp; 
<input type=checkbox name=c3 value=yes >JavaScript</td></tr>
<tr bgcolor='#ffffff'><td>Select one day</td><td><select name=s1>
<option value='' >Select One</option>

<option value=Mon >Mon</option>
<option value=Tue >Tue</option>
<option value=Wed >Wed</option>
<option value=Thu >Thu</option>
<option value=Fri >Fri</option>
<option value=Sat >Sat</option>
<option value=Sun >Sun</option>
</select> </td></tr>

<tr><td colspan=2><input type=submit value=Submit> </td></tr>
</table></form>
You can read the above code and remember each component has its own unique name which we can use to collect the data entered by user. Radio buttons of one group will have same name as one of them will be selected. You can read all form components in our html form section.

Here is the code for demo-basic-form2.php
<html>
<head>
<title>Demo of basic form design and submission to collect data by PHP</title>
<META NAME="DESCRIPTION" CONTENT="Basic form submission ">
<META NAME="KEYWORDS" CONTENT="Basic form validation, demo">

</head>

<body>
<?Php
$name=$_POST['t1'];    // Name tag value
$todo=$_POST['todo']; // hidden tag value
$gender=$_POST['gender']; // Value of gender, male or female
$c1=$_POST['c1']; // checkbox for PHP
$c2=$_POST['c2']; // checkbox of ASP
$c3=$_POST['c3']; // checkbox for JavaScript
$s1=$_POST['s1']; //  Drop down selection box for day

//// Let us display the variables /////

echo "<pre>
Name = $name
Todo = $todo
gender = $gender
PHP = $c1
ASP = $c2
JavaScript = $c3
Day = $s1
</pre>";
?>
</body>
</html>
After getting the data in receiving page and creating variables, we can store the data in MySQL table or store in simple text file. Using this concept we have created a signup script where members can register. To understand the data inserting or adding process in Database we have different scripts.
User Signup Script PHP Data Object to add records to Database
PHP Form DEMO of the form basic using PHP PHP sticky Form
Validating different input types in a form
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Post your comments , suggestion , error , requirements etc here





    PHP video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer