this is part of the validation codes
$errors = validateFields($_POST, $rules);
// if there were errors, re-populate the form fields
if (!empty($errors))
{
$fields = $_POST;
}
// no errors! redirect the user to the thankyou page (or whatever)
else
{
$message = “”;
}
?>
[U]these will be the codes for the forms and insertion of data
[/U]<html>
<head>
<meta http-equiv=“Content-Type” content=“text/html; charset=iso-8859-1” />
<title>AddContact</title>
<style type=“text/css”>
<!–
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: small;
}
.style2 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: smaller;
}
–>
</style></head>
<body>
<?php
//connecting to database
include (“config.php”);
include (“opendb.php”);
{
//get values from form
$firstName = mysql_real_escape_string($_POST[‘firstName’]);
$lastName = mysql_real_escape_string($_POST[‘lastName’]);
//insert data into MYSQL
$sql= “INSERT INTO contacts (firstName,lastName) VALUES “;
$sql.= “('”.$firstName.”', '”.$lastName.“')”;
//Execute SQL Statement and store results as a recordset
$result= mysql_query($sql, $conn) or die (mysql_error());
if ( !$result )
{
echo ‘the data could not be inserted’;
}
else
{
echo “<p> the data has been inserted successfully</p>.”;
}
//close connection
mysql_close($conn);
}
?>
<table width=“537” height=“242” border=“1” cellpadding=“1” cellspacing=“1”>
<form id=“form1” name=“form1” method=“post” action=“<?php echo $_SERVER[‘PHP_SELF’]; ?> “>
<tr>
<td colspan=“2”><span class=“style1”>Add Contact </span></td>
</tr>
<tr>
<td colspan=“2”> </td>
</tr>
<tr>
<td width=“140”><span class=“style2”>First Name : </span></td>
<td width=“384”>
<input name=“firstName” type=“text” id=“firstName” value=”<?=$fields[‘firstName’]?>” size=“50” /> </td>
</tr>
<tr>
<td><span class=“style2”>Last Name : </span></td>
<td>
<input name=“lastName” type=“text” id=“lastName” value=“<?=$fields[‘lastName’]?>” size=“50” /> </td>
</tr>
<tr>
</tr>
<tr>
<td> </td>
<td><input name=“AddContact” type=“submit” id=“AddContact” value=“AddContact”>
</form>
</td>
</tr>
</table>
</body>
</html>