Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2004
    Location
    pittsburgh/cleveland
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    exit() ending all html script after it

    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 Code:
    <?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>

  • #2
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.
    Omnis mico antequam dominus Spookster!

  • #3
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    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.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •