I have a form i will use to register new people and when I click the
submit button, the form just shows itself. It is supposed to show a
message showing field errors if you leave fields blank etc. so
submitting the empty form should show error message in red , then show
form, but all it does is show form. I checked the variable to make
shore they ere ok and they are fine. i believe it is a logical error
with my if else.... I eved modularized everything by using functions
and the same results.
if any one sees the logical error, let me know. Here the code:
<?php
function showmessage() {
// Check to make sure they entered a valid email address.
if (eregi("^([[:alnum:]]|_|\.|-)+@([[:alnum:]]|\.|-)+(\.)([a-z]{2,4})$",
$HTTP_POST_VARS['emailfield'])) {
$d = TRUE;
} else {
$d = FALSE;
$message1[] = "The email address you entered is not valid.";
}
return;
}
function checkfields(){
$year = $HTTP_POST_VARS['yearfield'];
$month = $HTTP_POST_VARS['monthfield'];
$day = $HTTP_POST_VARS['dayfield'];
$dobfield = $year.$month.$d ay;
// Check the last name.
if (eregi ("^([[:alpha:]]|-|')+$", $HTTP_POST_VARS['usernamefield']))
{
$a = TRUE;
} else {
$a = FALSE;
$message1[] = "Please enter a correct username. I.e; EricDerouen
that consists only of letters.";
}
// Check the first name.
if (eregi ("^([[:alpha:]]|-|')+$",
$HTTP_POST_VARS['firstnamefield '])) {
$b = TRUE;
} else {
$b = FALSE;
$message1[] = "Please enter a First Name that consists only of
letters.";
}
// Check the last name.
if (eregi ("^([[:alpha:]]|-|')+$", $HTTP_POST_VARS['lastnamefield']))
{
$c = TRUE;
} else {
$c = FALSE;
$message1[] = "Please enter a Last Name that consists only of
letters.";
}
// Check to make sure they entered a valid email address.
if (eregi("^([[:alnum:]]|_|\.|-)+@([[:alnum:]]|\.|-)+(\.)([a-z]{2,4})$",
$HTTP_POST_VARS['emailfield'])) {
$d = TRUE;
} else {
$d = FALSE;
$message1[] = "The email address you entered is not valid.";
}
// Check the password field.
if ($HTTP_POST_VAR S['passwordfield'] <> "") {
$e = TRUE;
} else {
$e = FALSE;
$message1[] = "Please enter a password.";
}
// Check validate password.
if ($HTTP_POST_VAR S['confirmfield'] =
$HTTP_POST_VARS['$passwordfield ']) {
$f = TRUE;
} else {
$f = FALSE;
$message1[] = "The password you entered do not match the password
you confirmed.";
}
// Check the City.
if (eregi ("^([[:alpha:]]|-|')+$", $HTTP_POST_VARS['cityfield'])) {
$g = TRUE;
} else {
$g = FALSE;
$message1[] = "Please enter a City that consists only of letters.";
}
// Check the state.
if (eregi ("^([[:alpha:]]|-|')+$", $HTTP_POST_VARS['statefield'])) {
$h = TRUE;
} else {
$h = FALSE;
$message1[] = "Please enter a State that consists only of letters.";
}
if (ereg("([0-9]{4})-([0-9]{2})-([0-9]{2})",$dobfield ))
{
$i = TRUE;
} else {
$i = FALSE;
$message1[] = "The BIRTHDATE you entered is invalid.";
}
}
function connectandinser t(){
$hostname = "localhost" ;
$database = ""; //intentionally left out!
$username = "";
$password = "";
$connection = mysql_connect($ hostname, $username, $password) or
die(mysql_error ());
$db = mysql_select_db ($database, $connection) or die ("could not
connect to database");
//Time to insert variables from form into main table.
$query = "insert into main
(userneme,last, first,dob,atten ding,email,addr ess,city,state, phone,
cellphone,atten dedlast,passwor d) values
('$usernamefiel d','$lastnamefi eld','$firstnam efield','$dobfi eld','$radiobut ton2',
'$emailfield',' $addressfield', '$cityfield','$ statefield','$p honefield','$ce llphone','$radi obutton3','$pas swordfield')";
$result = mysql_query($qu ery)
or die ("could not execute query.");
}
function sendemails(){
//send email to customer using email he submitted.
$message1 = "{$firstnamefie ld},\n \nThank you for registering For the
Derouen Family Reunion.\n
You have been pre-registered to attend. A committee member will be
contacting you. \n
You will be also receive the latest Reunion via the E-Mail address
provided.\n
And don't forget to check our family reunion web-site from time to
time.\n \nReunion Committee\n Databaseindays. com";
if (mail($emailfie ld,"Re: Your Derouen Family Reunion",$messa ge1))
{echo "+";}
else {echo "-";}
//now why not send one to ourself with all the information.
$message1 = "First name: $firstnamefield \nLast Name:
$lastnamefield\ nEmail: $emailfield\nPh one: $phonefield\n
cellphone: $cellphone\nDOB : $dobfield\n$Add ress: $addressfield\n City:
$cityfield\nSta te: $statefield\nZi p: $zipfield\n
Attending: $radiobutton2\n Attended Last: $radiobutton3\n ";
if (mail("in**@dat abaseindays.com ","New Registration Form for Derouen
Family Reunion",$messa ge1))
{echo "+";}
else {echo " -";}
}
//*************** *************** *************** *************** *************** *******
if (!isset($_POST['submitbut']))
{
include("showre g_form.html");
exit;
}
checkfields();
if ($a AND $b AND $c AND $d AND $e AND $f AND $g AND $h AND $i)
{
connectandinser t();
sendemails();
echo "all went well. inserted and emailed your ass";
}
else
{
showmessage();
include("showre g_form.html");
}}
?>