We will now add records to the Patient and Disease tables using the form that we created previously. Look at the second patient information form, and open the form where the validation was done.
At one point in the code is the line:
if($ok) echo 'The information is complete.<BR>'; //can be entered in database
We will modify the code so that the record is added to the database as follows:
The important code is shown below. The entire form can be seen at addPatient.txt
$diseaseList=array('Asthma','Cancer','Diabetes','Hypertension','Emphysema','Cerebral Palsy','Drug abuse','Gastritis');
We will use this array to generate the form:
foreach($diseaseList as $id=>$info) {
echo '<label>';
echo '<input name="disease[]" type="checkbox" id="'.$info.'" value="'.$info.'"';
if(isset($disease[$id])) echo ' checked="checked" ';
echo '/>'.$info.'</label><br />';
}
Now we will be able to loop through the $_POST disease array to add the diseases to the table.