...

View Full Version : exit() ending all html script after it



jonv
01-05-2004, 02:11 AM
I'm trying to figure out how to make this script work because the exit functions i have are ending all the html code as well--here is the code including the html after the php section:



<?php
include 'db.php';

// Define post fields into simple variables
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email_address = $_POST['email_address'];
$username = $_POST['username'];
$info = $_POST['info'];

/* Let's strip some slashes in case the user entered
any escaped characters. */

$first_name = stripslashes($first_name);
$last_name = stripslashes($last_name);
$email_address = stripslashes($email_address);
$username = stripslashes($username);
$info = stripslashes($info);


/* Do some error checking on the form posted fields */

if((!$first_name) || (!$last_name) || (!$email_address) || (!$username)){
echo 'You did not submit the following required information! <br />';
if(!$first_name){
echo "First Name is a required field. Please enter it below.<br />";
}
if(!$last_name){
echo "Last Name is a required field. Please enter it below.<br />";
}
if(!$email_address){
echo "Email Address is a required field. Please enter it below.<br />";
}
if(!$username){
echo "Desired Username is a required field. Please enter it below.<br />";
}
include 'join_form.php'; // Show the form again!
/* End the error checking and if everything is ok, we'll move on to
creating the user account */
exit(); // if the error checking has failed, we'll exit the script!
}

/* Let's do some checking and ensure that the user's email address or username
does not exist in the database */

$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);

if(($email_check > 0) || ($username_check > 0)){
echo "Please fix the following errors: <br />";
if($email_check > 0){
echo "<strong>Your email address has already been used by another member in our database. Please submit a different Email address!<br />";
unset($email_address);
}
if($username_check > 0){
echo "The username you have selected has already been used by another member in our database. Please choose a different Username!<br />";
unset($username);
}
include 'join_form.php'; // Show the form again!
exit(); // exit the script so that we do not create this account!
}
/*i took out the rest of the php because it sends out an email if everything is successful so far.*/

?>
</td>
</tr>
<tr>
<td height="265">&nbsp;</td>
</tr>
</table>
<table width="991" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="712" height="34" valign="top"><img src="../images/13.gif" width="712" height="34"></td>
<td width="113" valign="top"><a href="../about.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('About','','../images/14a.gif',1)"><img src="../images/14.gif" name="About" width="113" height="34" border="0"></a></td>
<td width="19" valign="top"><img src="../images/15.gif" width="19" height="34"></td>
<td width="113" valign="top"><a href="../sitemap.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Sitemap','','../images/16a.gif',1)"><img src="../images/16.gif" name="Sitemap" width="113" height="34" border="0"></a></td>
<td width="34" valign="top"><img src="../images/17.gif" width="34" height="34"></td>
</tr>
</table>
<table width="991" border="0" cellpadding="0" cellspacing="0" bgcolor="6666666">
<!--DWLayoutTable-->
<tr>
<td width="991" height="139" valign="top"><div align="center"><br>
Copyright 2003, 2004</div></td>
</tr>
</table>
</body>
</html>

Mhtml
01-05-2004, 03:00 AM
The best way to do it is to split everything into dependant functions so that you can just do a logical boolean if statement to decide if you should continue to the next part of your code ... This also makes it much more managable.

firepages
01-05-2004, 04:01 AM
exit() is an alias for die() , eg after its called the script will die & ho further output sent , so its doing exactly what you are telling it to do.

use your if/else or switch constructs to decide what does or does not get shown , only call exit(); when you have output all that you actually want to output.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum