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>
table row does not appear
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
-
Tubbietoeter
- Forum Contributor
- Posts: 149
- Joined: Fri Mar 14, 2003 2:41 am
- Location: Germany
If I remove the exit (), the information submitted is posted to the database even if there are errors. How can I alter the statement to maintain visible the last row of the table but yet meet all the criteria before the info is submitted to the database? In other words what should I replace exit() with?
Thanks
Thanks
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
You could do:
instead of
and it does make it a lot easier to read your code if you use the PHP tags to surround it.
Mac
Code: Select all
} else {
$sql = "INSERT INTO USERS (first_name, last_name, email_address, username, password, signup_date)
VALUES('$first_name', '$last_name', '$email_address', '$username', '$password', NOW())";
@mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
if (mysql_affected_rows() < 1) {
echo 'There has been an error creating your account. Please contact the webmaster.';
user_form();
} else {
echo '<p><font color="#FFFFFF" size="3" face="Verdana, Arial, Helvetica, sans-serif">Successfully submitted, please <a href="IAM_login.php">login </a> now</font></p>';
}
}Code: Select all
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>';
}Mac
Thanks twigletmac, your suggestion worked very well. I will also send all future code in PHP tags.
I have another quick question for you, which I know must be quite simple but I am such a new PHP user that I am not sure of the answer. If instead of the following:
I simply wanted to go to "register.php" instead of writing the sucessfully submitte response, how would I do that?
Thanks again for your help...you have been a great help on several occaisons.
I have another quick question for you, which I know must be quite simple but I am such a new PHP user that I am not sure of the answer. If instead of the following:
Code: Select all
<?php
} else {
echo '<p><font color="#FFFFFF" size="3" face="Verdana, Arial, Helvetica, sans-serif">Successfully submitted, please <a href="IAM_login.php">login </a> now</font></p>';
}
?>Thanks again for your help...you have been a great help on several occaisons.