yobo Posted October 13, 2008 Share Posted October 13, 2008 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"); } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/128239-how-would-i-get-multiple-header-functions/ Share on other sites More sharing options...
wildteen88 Posted October 13, 2008 Share Posted October 13, 2008 I would be helpful if you we knew what error that script produces. Quote Link to comment https://forums.phpfreaks.com/topic/128239-how-would-i-get-multiple-header-functions/#findComment-664145 Share on other sites More sharing options...
yobo Posted October 13, 2008 Author Share Posted October 13, 2008 Headers already sent to output... Quote Link to comment https://forums.phpfreaks.com/topic/128239-how-would-i-get-multiple-header-functions/#findComment-664176 Share on other sites More sharing options...
wildteen88 Posted October 13, 2008 Share Posted October 13, 2008 That is due to an error on your part. header() cant be used after any form of output is sent to the browser. Quote Link to comment https://forums.phpfreaks.com/topic/128239-how-would-i-get-multiple-header-functions/#findComment-664183 Share on other sites More sharing options...
vicodin Posted October 13, 2008 Share Posted October 13, 2008 Wildteen is correct. Have the form go to another page and validate all the info there and then use the header function. Quote Link to comment https://forums.phpfreaks.com/topic/128239-how-would-i-get-multiple-header-functions/#findComment-664187 Share on other sites More sharing options...
redarrow Posted October 13, 2008 Share Posted October 13, 2008 it can be done but it not a good programming method not a way out code but works! <?php ob_start(); // top off page ob_flush(); // end off page ?> Quote Link to comment https://forums.phpfreaks.com/topic/128239-how-would-i-get-multiple-header-functions/#findComment-664199 Share on other sites More sharing options...
yobo Posted October 13, 2008 Author Share Posted October 13, 2008 Wildteen is correct. Have the form go to another page and validate all the info there and then use the header function. Thats what I am trying to do my html form is on one page and this page is called the process.php page Quote Link to comment https://forums.phpfreaks.com/topic/128239-how-would-i-get-multiple-header-functions/#findComment-664207 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.