<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Add New DJ</title>
<style type="text/css">
.error {font-family: "courier new"; color: red; font-size: 10pt;}
</style>
</head>
<body>
<?php
//include 'include\db.inc.php';
$name = $_POST['name'];
$age = $_POST['age'];
$location = $_POST['location'];
$intrests = $_POST['intrests'];
$yearsofmixing = $_POST['yearsofmixing'];
$playedat = $_POST['playedat'];
$msn = $_POST['msn'];
$email = $_POST['email'];
// Validation Routine
$error = 0;
$error_mes = '';
if (strlen($_POST['name']) <
1) {$error =
$error +
1;
$error_mes .=
"Sorry, no name entered\n";
} if (strlen($_POST['age']) <
1) {$error =
$error +
1;
$error_mes .=
"Sorry, no age entered\n";
} if (strlen($_POST['location']) <
1) {$error =
$error +
1;
$error_mes .=
"Sorry, no location entered\n";
} if (strlen($_POST['intrests']) <
1) {$error =
$error +
1;
$error_mes .=
"Sorry, no interests entered\n";
} if (strlen($_POST['yearsofmixing']) <
1) {$error =
$error +
1;
$error_mes .=
"Sorry, no years of mixing entered\n";
} if (strlen($_POST['playedat']) <
1) {$error =
$error +
1;
$error_mes .=
"Sorry, no places played at entered\n";
} // if (strlen($_POST['msn']) < 1) {$error = $error + 1; $error_mes .= "Sorry, no msn name entered\n";} // This isn't an error --- is it?
if (strlen($_POST['email']) <
1) {$error =
$error +
1;
$error_mes .=
"Sorry, no email entered\n";
}
if ($error >= 1) {;}
else { // If no errors, enter data into database
$sql = "INSERT INTO dj SET
name='$name',
age='$age',
location='$location',
intrests='$intrests',
yearsofmixing='$yearsofmixing',
playedat='$playedat',
msn='$msn',
email='$email'";
echo '<p>New DJ Added! Thank you.</p>';
} else {
echo '<p>Database Error - New DJ not Added</p>';
}
}
?>
<?php
if ($_POST){
if ($error >= 1)
{ // Prints any errors at the beginning of the page
// echo "<PRE>";
// echo "<span style=\"color: red;\">Errors!!!\n\n";
// echo $error_mes;
// echo "</span>";
// echo "</PRE>";
}
}
?>
<?php if ($error > 0) { ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Enter the new DJ Information: </p>
<label for="name">Enter DJ Name:<br />
<input type="text" name="name" id="name" value="<?php if (strlen($name) > 0) {echo $name;} ?>" /></label><br />
<span id="error_name" class="errormessage">
<?php if ($_POST &&
strlen($_POST['name']) <
1) {echo "<P class=\"error\">No name entered.</P>";
} ?> </span>
<label for="age">Enter DJ Age:<br />
<input type="text" name="age" id="age" value="<?php if (strlen($age) > 0) {echo $age;} ?>" /></label><br />
<span id="error_age" class="errormessage">
<?php if ($_POST){ if (preg_match('/^[0-9]+$/',
$age)) {;
} else {echo "<P class=\"error\">Age must be digits only.</P>";
} } ?> </span>
<label for="location">Enter DJ Location:<br />
<input type="text" name="location" id="location" value="<?php if (strlen($location) > 0) {echo $location;} ?>" /> </label><br />
<span id="error_location" class="errormessage">
<?php if ($_POST &&
strlen($_POST['location']) <
1) {echo "<P class=\"error\">No location entered.</P>";
} ?> </span>
<label for="intrests">Enter DJ Intrests:<br />
<textarea name=
"intrests" rows=
"10" cols=
"25" id=
"intrests"><?php
if (strlen($intrests) >
0) {echo $intrests;
} ?></textarea></label><br />
<span id="error_intrests" class="errormessage">
<?php if ($_POST &&
strlen($_POST['intrests']) <
1) {echo "<P class=\"error\">No interests entered.</P>";
} ?> </span>
<label for="mixing">Enter DJ Years of Mixing:<br />
<input type="text" name="yearsofmixing" id="mixing" value="<?php if (strlen($yearsofmixing) > 0) {echo $yearsofmixing;} ?>" /></label><br />
<span id="error_mixing" class="errormessage">
<?php if ($_POST){ if (preg_match('/^[0-9]+$/',
$yearsofmixing)) {;
} else {echo "<P class=\"error\">Years of mixing must be digits only.</P>";
} } ?> </span>
<label for="playedat">Enter DJ Played At:<br />
<textarea name=
"playedat" rows=
"10" cols=
"25" id=
"playedat"><?php
if (strlen($playedat) >
0) {echo $playedat;
} ?></textarea></label><br />
<span id="error_played" class="errormessage">
<?php if ($_POST &&
strlen($_POST['playedat']) <
1) {echo "<P class=\"error\">No places played at entered.</P>";
} ?> </span>
<p>Enter Contact Details: </p>
<label for="msn"> Enter DJ MSN:<br />
<input type="text" name="msn" id="msn" value="<?php if (strlen($msn) > 0) {echo $msn;} ?>" /></label><br />
<span id="error_msn" class="errormessage">
<?php
if (strlen($msn) >
0){ // MSN email address not required // This regex from http://www.smartwebby.com/PHP/emailvalidation.asp
if (ereg("^[^@ ]+@[^@ ]+\.[^@ ]+$",
$msn)) {;
} else {echo "<P class=\"error\">This is invalid MSN email address.</P>";
} }
?>
</span>
<label
for=
"mail">Enter DJ E-
Mail:<br />
<input type="text" name="email" id="mail" value="<?php if (strlen($email) > 0) {echo $email;} ?>" /></label><br />
<span id="error_email" class="errormessage">
<?php
if ($_POST){
// This regex from http://www.smartwebby.com/PHP/emailvalidation.asp
if (ereg("^[^@ ]+@[^@ ]+\.[^@ ]+$",
$email)) {;
} else {echo "<P class=\"error\">This is invalid email address.</P>";
} }
?>
</span>
<input type="submit" name="add_dj" value="Add DJ" id="adddj" />
</form>
<?php }?>
</body>
</html>