I have a script embedded in a table cell. When the script is executed and there is an error message (which appears in the cell as well) the last row of the table does not appear. If the script is executed and all information is submitted correctly (i.e. no error messages) the last row of the table appears just fine.
Any ideas of why the row does not appear if there are error messages?
Thanks
<?php include ('connlogin.php');?>
<html>
<head>
<title>Fauna Database Registration</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table width="600" align="center" cellpadding="1" cellspacing="1">
<!--DWLayoutTable-->
<tr bgcolor="003366">
<td colspan="2" valign="top"><!--DWLayoutEmptyCell--> </td>
</tr>
<tr>
<td width="213" valign="top" bgcolor="003366"><!--DWLayoutEmptyCell--> </td>
<td width="374" valign="top" bgcolor="003366">
<?php
require_once 'function3.php';
$first_name = $POST['first_name'];
$last_name = $POST['last_name'];
$email_address = $POST['email_address'];
$password = $POST['password'];
$password2 = $POST['password2'];
$username = $POST['username'];
$first_name = stripslashes($first_name);
$last_name = stripslashes($last_name);
$email_address = stripslashes($email_address);
$username = stripslashes($username);
// has the form been submitted?
if (isset($POST['submit'])) {
// the form has been submitted
// perform data checks.
$sql_email_check = mysql_query("SELECT email_address FROM users WHERE email_address='$email_address'");
$sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'");
$email_check = mysql_num_rows($sql_email_check);
$username_check = mysql_num_rows($sql_username_check);
$error_str = ''; // initialise $error_str as empty
if (empty($POST['first_name'])) $error_str .= '<li><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">You did not enter your first name</font></li>';
if (empty($POST['last_name'])) $error_str .= '<li><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">You did not enter your last name</font></li>';
if (empty($POST['email_address'])) $error_str .= '<li><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">You did not enter your E-mail address</font></li>';
if (empty($POST['username'])) $error_str .= '<li><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">You did not enter your desired username</font></li>';
if (empty($POST['password'])) $error_str .= '<li><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">You did not enter your desired password</font></li>';
// more checks
if ($POST['password'] != $POST['password2']) $error_str .= '<li><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Your passwords do not match.</font></li>';
if (!preg_match("/.@...*/", $POST['email_address']) | preg_match("/(<|> )/", $POST['email_address'])) $error_str .= '<li><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Invalid E-mail address</font></li>';
if ($email_check > 0) $error_str .= '<li><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">E-mail address already in use, select another.</font></li>';
if ($username_check > 0) $error_str .= '<li><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Username already in use, select another.</font></li>';
// we could also strip any HTML from the variables, convert it to entities, have a maximum character limit on the values, etc etc, but this is just an example.
// now, have any of these errors happened? We can find out by checking if $error_str is empty
if (!empty($error_str)) {
// errors have occured, halt execution and show form again.
echo '<p><div align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">There were errors in the information you entered, they are listed below:</font></div></p>';
echo '<ul>'.$error_str.'</ul>';
// show form again
user_form();
exit; // die
}
$sql = mysql_query("INSERT INTO USERS (first_name, last_name, email_address, username, password, signup_date)
VALUES('$first_name', '$last_name', '$email_address', '$username', '$password', now())") or die (mysql_error());
if(!$sql){
echo 'There has been an error creating your account. Please contact the webmaster.';
user_form();
} else {
echo '<p> </p><p> </p><p> </p><font color="#FFFFFF" size="3" face="Verdana, Arial, Helvetica, sans-serif">Successfully submitted, please <a href="IAM_login.php">login </a> now</font>';
}
}
?>
</td>
</tr>
<tr bgcolor="#009999">
<td colspan="2" valign="top">text......</td>
</tr>
</table>
</body>
</html>