I finally got the registration form to work. Code is below. It is
actually a good example to use to register people. I believe my
problem was the fact that I showed the form using an
"include(showform.php)". Since I had the form calling itself if there
was a problem, this caused a problem showing the errors. Once I
included the code to show form all in the same script, this made
everything fire like it was supposed to. This script displays a form
and checks the fields for valid info then inserts into a DB then
amails the user his registration info then emails you a new person
registered than thanks the user. thanks to all tha helped:
<?php
//************************************************** ********************************
function thankyou(){
?>
<html>
<body bgcolor="#FFFFFF">
<div align="center"><font color="#669933" size="6" face="Comic Sans
MS">Thank
you </font> </div>
<p align="center"><font color="#669933" size="4" face="Comic Sans
MS">for registering
for the website.<br>
You will soon receive an email confirmation of your
registration.<br>
You can login to the site now using the username and password you
provided.<br>
A committee member will also be contacting you.
</font></p>
<h3 align="center"> </h3>
<h3 align="center">Email us at: <a
href="mailto:info@xxx.com">info@xxx.Com</a></h3>
<p align="center"><font size="4"> | <a href="login.php">Login
</a> | <a href="index.html">Home</a> |</font></p>
</body>
</html>
<?php
}
function connectdb(){
$hostname = "localhost";
$database = "xxx";
$username = "xxx";
$password = "xxx";
$connection = mysql_connect($hostname, $username, $password) or
die(mysql_error());
$db = mysql_select_db($database, $connection) or die ("could not
connect to database");
}
function showform(){
?>
<html>
<head>
<title>Register to the Derouen Family Web-Site</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0"
marginheight="0">
<form name="form2" method="post" action= "register.php" >
<table width="90%" border="0" cellpadding="8" bgcolor="#FFFFFF">
<tr>
<td colspan="3" bgcolor="#CCCCCC">
<b>Register for the xxx </b></td>
</tr>
<tr valign="top">
<td align="right" bgcolor="#CCCCCC" nowrap>
User Name<font size="-2">*</font></td>
<td colspan="2" bgcolor="#FFFFFF"> <input
name="usernamefield" type="text" id="usernamefield" size="25"
maxlength="25" value="<?php echo $usernamefield ?>">
<br>
<font size="-2">*</font>Enter a user name.
Ex. xxx <font size="-1"> </font></td>
</tr>
<tr valign="top">
<td align="right" bgcolor="#CCCCCC">
Password<font size="-2">*</font></td>
<td colspan="2" bgcolor="#FFFFFF"> <input
name="passwordfield" type="password" id="passwordfield" size="25"
maxlength="25"> </td>
</tr>
<tr valign="top">
<td align="right" bgcolor="#CCCCCC">
Confirm<br>
Password</td>
<td colspan="2" bgcolor="#FFFFFF"> <input
name="confirmfield" type="password" id="confirmfield" size="25"
maxlength="25">
<br>
<font size="-2">*</font><font size="-1">Confirm the password
you entered </font></td>
</tr>
<tr valign="top">
<td align="right" bgcolor="#CCCCCC">
Name</td>
<td width="43%" bgcolor="#FFFFFF"> <input
name="firstnamefield" type="text" id="firstnamefield" size="25"
maxlength="25" value="<?php echo $firstnamefield ?>">
<br> <font size="-1">First</font></td>
<td width="46%" bgcolor="#FFFFFF"> <input
name="lastnamefield" type="text" id="lastnamefield" size="25"
maxlength="25" value="<?php echo $lastnamefield ?>">
<br> <font size="-1">Last</font></td>
</tr>
<tr valign="top">
<td align="right" bgcolor="#CCCCCC">
Email</td>
<td colspan="2" bgcolor="#FFFFFF"> <input
name="emailfield" type="text" id="emailfield" size="50" maxlength="50"
value="<?php echo $emailfield ?>">
Ex.
JSmith@Comcast.net </td>
</tr>
<tr valign="top">
<td align="right" bgcolor="#CCCCCC">
Phone</td>
<td colspan="2" bgcolor="#FFFFFF"><input name="phonefield"
type="text" id="phonefield" size="15" maxlength="15" value="<?php echo
$phonefield ?>">
Cell Phone
<input name="cellphonefield" type="text" id="cellphonefield"
size="15" maxlength="15" value="<?php echo $cellphonefield ?>">
</td>
</tr>
<tr valign="top">
<td align="right" bgcolor="#CCCCCC">
Address</td>
<td colspan="2" bgcolor="#FFFFFF"> <input
name="addressfield" type="text" id="addressfield" size="50"
maxlength="50" value="<?php echo $addressfield ?>">
</td>
</tr>
<tr valign="top">
<td align="right" bgcolor="#CCCCCC">
City/State/Zip</td>
<td colspan="2" bgcolor="#FFFFFF"> <input
name="cityfield" type="text" id="cityfield" size="25" maxlength="25"
value="<?php echo $cityfield ?>">
State:
<input name="statefield" type="text" id="statefield" size="2"
maxlength="2" value="<?php echo $statefield ?>">
Zip:
<input name="zipcodefield" type="text" id="zipcodefield"
size="10" maxlength="10" value="<?php echo $zipcodefield ?>">
</td>
</tr>
<tr valign="top">
<td align="right" bgcolor="#CCCCCC">
Gender</td>
<td colspan="2" bgcolor="#FFFFFF"> <p>
<input type="radio" name="radiobutton1" value="male">
Male
<input type="radio" name="radiobutton1" value="female">
Female </p></td>
</tr>
<tr valign="top">
<td align="right" bgcolor="#CCCCCC">
Birth Date</td>
<td colspan="2" bgcolor="#FFFFFF"> <table border="0"
cellspacing="2" cellpadding="0">
<tr align="left">
<td><input name="monthfield" type="text"
id="monthfield" size="2" maxlength="2"></td>
<td><input name="dayfield" type="text" id="dayfield"
size="2" maxlength="2"></td>
<td><input name="yearfield" type="text" id="yearfield"
size="4" maxlength="4"></td>
</tr>
<tr align="left">
<td>MM</td>
<td>DD</td>
<td>YYYY</td>
</tr>
</table></td>
</tr>
<tr valign="top">
<td colspan="3"> <p>Do you plan on attending the next
?.<br>
<input type="radio" name="radiobutton2" value="yes">
Yes<br>
<input type="radio" name="radiobutton2" value="no">
No</p>
<p>Did you attend the last Reunion?. <br>
<input type="radio" name="radiobutton3" value="yes">
Yes<br>
<input type="radio" name="radiobutton3" value="no">
No</p></td>
</tr>
<tr valign="top" bgcolor="#FFFFFF">
<td colspan="3"><input type="submit" name="submitbut"
value="Submit Registration Information"></td>
</tr>
</table>
</form>
</body>
</html>
<?php
}
if (isset ($_POST['submitbut'])){
//echo "but is set";
$year = $_POST['yearfield'];
$month = $_POST['monthfield'];
$day = $_POST['dayfield'];
$dobfield = $year.'-'.$month.'-'.$day;
//echo "this is the date : $dobfield";
//exit;
// Check the last name.
if (eregi ("^([[:alpha:]]|-|')+$", $_POST['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:]]|-|')+$", $_POST['firstnamefield'])) {
$b = TRUE;
} else {
$b = FALSE;
$message1[] = "Please enter a First Name that consists only of
letters.";
}
// Check the last name.
if (eregi ("^([[:alpha:]]|-|')+$", $_POST['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})$",
$_POST['emailfield'])) {
$d = TRUE;
} else {
$d = FALSE;
$message1[] = "The email address you entered is not valid.";
}
// Check the password field.
if ($_POST['passwordfield'] <> "") {
$e = TRUE;
} else {
$e = FALSE;
$message1[] = "Please enter a password.";
}
// Check validate password.
if ($_POST[confirmfield] = $_POST['passwordfield']) {
$f = TRUE;
} else {
$f = FALSE;
$message1[] = "The password you entered do not match the password
you confirmed.";
}
// Check the City.
if (eregi ("^([[:alpha:]]|-|')+$", $_POST['cityfield'])) {
$g = TRUE;
} else {
$g = FALSE;
$message1[] = "Please enter a City that consists only of letters.";
}
// Check the state.
if (eregi ("^([[:alpha:]]|-|')+$", $_POST['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.";
}}
if ($a and $b and $c and $d and $e and $f and $g and $h and $i)
{
connectdb();
//Time to insert variables from form into main table.
$query = "insert into main
(username,last,first,dob,attending,email,address,c ity,state,zip,phone,
cellphone,attendedlast,password) values
('$usernamefield','$lastnamefield','$firstnamefiel d','$dobfield','$radiobutton2',
'$emailfield','$addressfield','$cityfield','$state field','$zipcodefield','$phonefield','$cellphone', '$radiobutton3','$passwordfield')";
$result = mysql_query($query)
or die ("could not execute query.");
$message = "{$firstnamefield},\n \nThank you for registering For the
Reunion.\n
You have been pre-registered to attend. A committee member will be
contacting you. \n
You will also receive the latest Reunion information via the E-Mail
address provided.\n
And don't forget to check our family reunion web-site from time to
time.\n
Your userid is: $username\nYour password is $passwordfield\n
\nReunion 2004 Committee.\n <a href="www.xxx.com/login.php">Login
Here</a>";
if (mail($emailfield,"Re: Your Reunion",$message))
{echo "+";}
else {echo "-";}
//now why not send one to ourself with all the information.
$message = "Username: $usernamefield\nFirst name:
$firstnamefield\nLast Name: $lastnamefield\nEmail: $emailfield\nPhone:
$phonefield
cellphone: $cellphonefield\nDOB: $dobfield\nAddress:
$addressfield\nCity: $cityfield\nState: $statefield\nZip:
$zipcodefield
Attending: $radiobutton2\nAttended Last: $radiobutton3\n
Username: $usernamefield";
if (mail("info@xxx.com","New Registration Form for Reunion",$message))
{echo "+";}
else {echo " -";}
thankyou();
}
else
{
//echo "some fields are wrong";
if ($message1) {
echo "<div align=center><font color=red><b>The following problems
occurred:</b><br />\n";
foreach ($message1 as $key => $value) {
echo "$value <br />\n";
}
}
showform();
} ?>