Her eis the full code
include 'error.inc';
include 'db.inc';
include 'clean.inc';
$id = clean($id, 5);
// Initialise an error string
$errorString = "";
// Clean and trim the POSTed values
foreach($HTTP_POST_VARS as $varname => $value)
$formVars[$varname] = trim(clean($value, 50));
// Vaildate the firstname
if (empty($formVars["Company"]))
// First name cannot be a null string
$errorString .=
"\n<br>The Company field cannot be blank.";
// Validate the Surname
if (empty($formVars["Logo"]))
// the user's surname cannot be a null string
$errorString .=
"\n<br>The Logo cannot be blank.";
// Validate the Address
if (empty($formVars["Strapline"]))
// the user's address cannot be a null string
$errorString .=
"\n<br>You must supply your strapline.";
// Validate the Activity
if (empty($formVars["Activity"]))
// the user's city cannot be a null string
$errorString .= "\n<br>You must supply an activity.";
// Validate Date of Birth
if (empty($formVars["Contact"]))
// the user's date of birth cannot be a null string
$errorString .= "\n<br>You must supply a contact name.";
// Validate Date of Birth
if (empty($formVars["Phone"]))
// the user's date of birth cannot be a null string
$errorString .= "\n<br>You must Phone no.";
// Validate Date of Birth
if (empty($formVars["Mobile"]))
// the user's date of birth cannot be a null string
$errorString .= "\n<br>You must supply a mobile.";
// Validate Date of Birth
if (empty($formVars["Email"]))
// the user's date of birth cannot be a null string
$errorString .= "\n<br>You must suppply an email address.";
if (empty($formVars["Add1"]))
// the user's email cannot be a null string
$errorString .= "\n<br>You must supply an address line 1.";
// Validate Date of Birth
if (empty($formVars["Add2"]))
// the user's date of birth cannot be a null string
$errorString .= "\n<br>You must suppply an address line 2.";
// Validate Date of Birth
if (empty($formVars["Add3"]))
// the user's date of birth cannot be a null string
$errorString .= "\n<br>You must suppply an address line 3.";
if (empty($formVars["Add4"]))
// the user's email cannot be a null string
$errorString .= "\n<br>You must supply an address line 4.";
// Validate Date of Birth
if (empty($formVars["Postcode"]))
// the user's date of birth cannot be a null string
$errorString .= "\n<br>You must suppply a postcode.";
if (empty($formVars["Text"]))
// the user's email cannot be a null string
$errorString .= "\n<br>You must supply some words on your company activity.";
// Now the script has finished the validation,
// check if there were any errors
if (!empty($errorString))
{
// There are errors. Show them and exit.
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd" >
<html>
<head><title>Customer Details Error</title></head>
<body bgcolor="white">
<h1>Customer Details Error</h1>
<?=$errorString?>
<br><a href="update2.php">Return to the customer form</a>
</body>
</html>
exit;
}
// If we made it here, then the data is valid
echo 'if we made it here then the data is valid';
if (!($link = @ mysql_pconnect($hostName,
$username,
$password)))
die("Could not connect to database");
if (!mysql_select_db($databaseName, $link))
showerror();
// Reassemble the date of birth into database format
$dob = " \"$parts[3]-$parts[2]-$parts[1]\"";
// Is this an update?
if (!empty($ID))
{
$query = "UPDATE feedback2 SET ".
"Company = \"" . $formVars["Company"] . "\", " .
"Logo = \"" . $formVars["Logo"] . "\", " .
"Strapline = \"" . $formVars["Strapline"] . "\", " .
"Activity = \"" . $formVars["Activity"] . "\", " .
"Contact = \"" . $formVars["Contact"] . "\", " .
"Phone = \"" . $formVars["Phone"] . "\", " .
"Mobile = \"" . $formVars["Mobile"] . "\", " .
"Email = \"" . $formVars["Email"] . "\", " .
"Add1 = \"" . $formVars["Add1"] . "\", " .
"Add2 = \"" . $formVars["Add2"] . "\", " .
"Add3 = \"" . $formVars["Add3"] . "\", " .
"Add4 = \"" . $formVars["Add4"] . "\", " .
"Postcode = \"" . $formVars["Postcode"] . "\", " .
"Text = \"" . $formVars["Text"] . "\", " .
" WHERE id = $id";
}
else
{
// Create a query to insert the customer
$query = "INSERT INTO feedback2
set id = NULL, " .
"Company= \"" . $formVars["Company"] . "\", " .
"Logo = \"" . $formVars["Logo"] . "\", " .
"Strapline = \"" . $formVars["Strapline"] . "\", " .
"Activity = \"" . $formVars["Activity"] . "\", " .
"Contact = \"" . $formVars["Contact"] . "\", " .
"Phone = \"" . $formVars["Phone"] . "\", " .
"Mobile = \"" . $formVars["Mobile"] . "\", " .
"Email = \"" . $formVars["Email"] . "\", " .
"Add1 = \"" . $formVars["Add1"] . "\", " .
"Add2 = \"" . $formVars["Add2"] . "\", " .
"Add3 = \"" . $formVars["Add3"] . "\", " .
"Add4 = \"" . $formVars["Add4"] . "\", " .
"Postcode = \"" . $formVars["Postcode"] . "\", " .
"Text = \"" . $formVars["Text"] . "\", " .
"birth_date = $dob;
}
// Run the query on the customer table
if (!(@ mysql_query ($query, $Link)))
showerror();
// Is this an insert?
if (empty($id))
// Find out the id of the new customer
$id = mysql_insert_id();
// Now show the customer receipt
// header("Location: customer_receipt.php?id=$id");
echo 'we made it to the end of example 6.8';