Warning: include_once(../../../../ad/resp-ad1.php): failed to open stream: No such file or directory in /home/icgpajzv/public_html/software/php/forms/examples/simple/index.php on line 11

Warning: include_once(): Failed opening '../../../../ad/resp-ad1.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/icgpajzv/public_html/software/php/forms/examples/simple/index.php on line 11

quest4tech.net

 

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