A SIMPLE FORM IN PHP
|
|
This article describes how to write simple basic form in php in a web page for data entry. The web page will first show a form which asks
for a name. When a name is entered and the form submitted, the page will be refreshed. After the refresh the web page will show the name that has been entered instead of the form.
|
<?php
// Check if the form has submitted data
if(!isset($_POST["action"] == 'submitted') ))
// if data has not been submitted, show the form for data entry
{
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<br> Enter a name: <input type="text" name="q" size="20" maxlength="50">
<input type="hidden" name="action" value="submitted">
<input type="submit" name="Submit" VALUE="Submit">
</form>
<?php
} else {
//if data has been submitted, show the data
$g1 = $_POST['q'];
echo "Name = ".$g1;
<?php
}
?>
|
When the form is submitted the data is sent to the server by the $_SERVER['PHP_SELF'] command.
From this simple example more complex forms and means of data entry can be designed.
TRY IT Click here for a working example of the form.
|
Main Index
(c) Compiled by B V Wood.
|
|
Main Index
UK SPONSERS
USA SPONSERS
|