Jump to content

Recommended Posts

Hey all,  how would go about having a header function in an if statment? what I would like to do is redirect user to sucess page if data was added if not have the user redirected to fail page, my coding is shown below. becuase if I do add the header function with the if statments it gives me an error messege.

 

<?php header("location: sucess.php");

include 'db.php';

include 'function.php';

 

if(!isset($_POST['register'])) {

 

 

 

} else {

 

  //init error variables

  $errorusername = false;

  $erroremail = false;

  $erroremailconf = false;

  $errorpassword = false;

  $errorpassconf = false;

 

  $username = isset($_POST['username']) ? trim($_POST['username']) : '';

  $email = isset($_POST['email']) ? trim($_POST['email']) : '';

  $emailconf = isset($_POST['emailconf']) ? trim($_POST['emailconf']) : '';

  $password = isset($_POST['password']) ? trim($_POST['password']) : '';

  $passconf = isset($_POST['passconf']) ? trim($_POST['passconf']) : '';

 

  if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) $erroremail = true;

  if(strlen($username) == '0') $errorusername = true;

  if(strlen($emailconf) == '0') $erroremailconf = true;

  if(strlen($password) == '0') $errorpassword = true;

  if(strlen($passconf) =='0') $errorpassconf = true;

 

  //display form again

  if($errorusername || $erroremail || $erroremailconf || $errorpassword || $errorpassconf) {

      showForm($errorusername,$erroremail,$erroremailconf,$errorpassword,$errorpassconf);

 

  } else {

     

      //check user email

     

      $query = mysql_query("SELECT email FROM users WHERE email = '".$email."'");

      if(@mysql_query($query)) $erroremail = true;

     

            $query2 = "INSERT INTO users SET

              username='$username',

              password='$password',

              email='$email'";

             

             

      if(@mysql_query($query2)) {

        header("location: good.php");

        }else{

            header("location: bad.php");

            } 

           

       

       

     

      }

     

 

}

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.