Forms

Forms will be the main way that we gather data for a database. We will use form input both to insert a new record in the database and to update an existing record.

We will consider the case of inserting a new record first. Let's suppose that our database has patient information including name, gender (M or F), phone number, address and date of birth. This information is fairly typical and will allow us to use most of the types of information that we can put on a form.

If you are using dreamweaver it is easiest to simply create the form in Dreamweaver, by selecting from the menu, insert form, textfield. A pop up window ask for the label, in this case we will start with firstname. Next Dreamweaver asks if you want a form tag. Answer yes. The form that is created will look like the one below:

The code for this is
<form id="form1" name="form1" method="post" action="">
  <label>First Name
    <input type="text" name="firstName" id="firstName" />
  </label>
</form>

In the empty quotes after action in the first line of the form, we will put the name of the page that is to receive the data from the form. The receiving page can be the same as the form itself or a different page. The address can be either absolute or relative. Let's suppose that the data from this form is to go to addPatient.php in the same directory as the form. The first line would say:
<form id="form1" name="form1" method="post" action="addPatient.php"> Because the name of the text field is firstName, the php script in addPatient.php would find this data in $firstName.

You can look at the complete patient information form. Be sure to experiment with the form and look at the page source. Part of the form and the output are generated using PHP. The page form1.php was also saved as form1.txt so that you can see the php code.


INDEX, Introduction, Form validation, Show Post variables
Next lesson: SessionsMAIN INDEX
EXAMPLES INDEX

Copyright © Zebra0.com
All rights reserved worldwide.

 
 

Introduction