I am trying to create a registration form and want a message to pop-up telling them if they've already registered (if their firstname, lastname and address are already in the mySQL database. Nothing I try is working... Can someone please HELP??? Thanks! Here is most of my PHP code. Sorry it's so long, wasn't sure what you need to see... THANKS!!!! This is driving me CRAZY!
<?php
if (isset($_POST['submitted'])) {
$errors = array(); //Initialize errors.
//Check for first name.
if(empty($_POST['firstname'])) {
$errors[] = 'You forgot to enter your first name.';
} else {
$fn = trim($_POST['firstname']);
}
//Check for last name.
if(empty($_POST['lastname'])) {
$errors[] = 'You forgot to enter your last name.';
} else {
$ln = trim($_POST['lastname']);
}
//Check for Address.
if(empty($_POST['address'])) {
$errors[] = 'You forgot to enter your street address.';
} else {
$address = trim($_POST['address']);
}
//Check for city.
if(empty($_POST['city'])) {
$errors[] = 'You forgot to enter your city.';
} else {
$city = trim($_POST['city']);
}
//Check for state.
if(empty($_POST['state'])) {
$errors[] = 'You forgot to enter a state.';
} else {
$state = trim($_POST['state']);
}
//Check for zip.
if(empty($_POST['zip'])) {
$errors[] = 'You forgot to enter your zip code.';
} else {
$zip = trim($_POST['zip']);
}
//Check for Home Phone.
if(empty($_POST['home_phone'])) {
$errors[] = 'You forgot to enter your Home Phone.';
} else {
$phone = trim($_POST['home_phone']);
}
//Check for time segment.
if(empty($_POST['time_segment'])) {
$errors[] = 'You forgot to select a time segment.';
} else {
$time = trim($_POST['time_segment']);
}
//Check for language.
if(empty($_POST['language'])) {
$errors[] = 'You forgot to select a language.';
} else {
$language = trim($_POST['language']);
}
//Check for agreement name.
if(empty($_POST['agreement_name'])) {
$errors[] = 'Please enter your name in the agreement.';
} else {
$agree_name = trim($_POST['agreement_name']);
}
//Check for consent.
if(empty($_POST['consent'])) {
$errors[] = 'You must agree to consent.';
} else {
$consent = trim($_POST['consent']);
}
if (empty($errors)) { //if everything is okay.
// Enter the user into the database
require_once('Connections/FDLFapps.php'); //connect to the db.
mysql_select_db($database_FDLFapps, $FDLFapps);
// Check for already registered
$query = "SELECT * from volunteer WHERE firstname='$fn'";
$result = mysql_query($query) or die(mysql_error());
if (!mysql_num_rows($result) == 0) {
//Make the query
$query = "INSERT INTO volunteer (firstname, lastname, address, apt_number, city, `state`, zip, home_phone, work_phone, email, age, accompanying_adult, under18_phone, under18_cellphone, shirt_size, time_segment, art_exhibits, childrens_area, volunteer_signin, gen_asst_runner, info_salesbooth, stage_assistant, religious, no_preference, nurses_station, arts_in_edu, add_comments, set_up_crew, setup_crew_time_segment, language, agreement_name, consent)
VALUES ('$fn', '$ln', '$address','$apt', '$city', '$state', '$zip', '$phone', '$cell', '$email', '$age', '$adult', '$adult_phone', '$adult_cell', '$shirt', '$time', '$art_ex', '$childrens', '$volunteer', '$runner', '$info_sales', '$stage', '$religious', '$no_preference', '$nurses', '$arts_edu', '$comments', '$set_up', '$setup_time', '$language', '$agree_name', '$consent' )";
$result = @mysql_query($query, $FDLFapps); // Run the query.
if ($result) { //If it ran ok.
//Print a message.
echo '<img src="images/SubBanner_Volunteer%5B1%5D.jpg" alt="Volunteer Header" name="VOLUNTEER" width="750" height="122" border="0" usemap="#VOLUNTEERMap">
<center><h1>Thank you! </h1>
<p> You are now registered.</p>
<p><a href="index.html">Festival Home</a> | <a href="volunteer.html">Volunteer Page</a></p></center>';
exit();
} else { //if it did not run ok.
echo '<h1> System Error </h1>';
echo '<p>' . mysql_error() . '<br><br> Query: ' . $query . '</p>';
exit();
}
} else { //already registered.
echo '<h1>OOPS!</h>
<p>You have already been registered.</p>';
}
} else { // Report the errors
echo '<h1>ERROR!!</h1> <p> The following error(s) occurrred:<br>';
foreach($errors as $msg) { //print each error.
echo " - $msg<br>\n";
}
echo '<p>Please try again</p>';
}
mysql_close(); // close the db connection.
}
?>