thesaleboat Posted July 30, 2008 Share Posted July 30, 2008 This is a user registration redirect page to verify that the passwords match so that they have entered the correct password... but i keep getting the same error: "Your Passwords do not match. Warning: Cannot modify header information - headers already sent by (output started at signup_ac.php:19) in signup_ac.php on line 21 I am trying to do a redirect that if the passwords do not match then redirect to signup.php, if they do redirect to login_success.php. Please help this is frustrating. <?php include('config.php'); require_once("functions.php"); $tbl_name=users; // values sent from form $name=$_POST['name']; $email=$_POST['email']; $password=$_POST['password']; $password_again=$_POST['password_again']; // Insert data into database if ($password == $password_again) { $sql="INSERT INTO $tbl_name (name, email, password) VALUES ('$name', '$email', '$password')"; $_SESSION["name"] = $name; $_SESSION["password"] = $password; $result=mysql_query($sql); redirect_to("login_success.php"); } else { echo "Your Passwords do not match."; //redirect_to("signup.php"); header("location:signup.php"); } ?> Quote Link to comment Share on other sites More sharing options...
dubc07 Posted July 30, 2008 Share Posted July 30, 2008 make sure there is no blank line on line one 1 or put <?php at the very top of code page. Quote Link to comment Share on other sites More sharing options...
dubc07 Posted July 30, 2008 Share Posted July 30, 2008 or instead of using header("location:signup.php"); use echo '<meta content="0; URL=../signup.php" http-equiv="Refresh" />'; Quote Link to comment Share on other sites More sharing options...
thesaleboat Posted July 30, 2008 Author Share Posted July 30, 2008 that is the entire page code. <?php is that the very top and the page is all php so that redirect will not work it gives me a new error: Parse error: syntax error, unexpected '<' in C:\xamp\xampplite\htdocs\JMISC_website\signup_ac.php on line 21 Quote Link to comment Share on other sites More sharing options...
revraz Posted July 30, 2008 Share Posted July 30, 2008 You are getting that error because you are Echo'g to the browser before the Header, which you can't do. So why echo it if you are going to redirect anyways, you'll never see the echo. Use the HTML redirect instead or remove the echo "Your Passwords do not match."; line. Quote Link to comment Share on other sites More sharing options...
dubc07 Posted July 30, 2008 Share Posted July 30, 2008 if your going to use <?php echo '<meta content="0; URL=../signup.php" http-equiv="Refresh" />';?> you can change the <meta content="0; 0 number to like 3 which is in seconds which will allow user to see your error before redirection. Quote Link to comment Share on other sites More sharing options...
dubc07 Posted July 30, 2008 Share Posted July 30, 2008 COPY AND PASTE THIS <?php include('config.php'); require_once("functions.php"); $tbl_name=users; // values sent from form $name=$_POST['name']; $email=$_POST['email']; $password=$_POST['password']; $password_again=$_POST['password_again']; // Insert data into database if ($password == $password_again) { $sql="INSERT INTO $tbl_name (name, email, password) VALUES ('$name', '$email', '$password')"; $_SESSION["name"] = $name; $_SESSION["password"] = $password; $result=mysql_query($sql); redirect_to("login_success.php"); } else { echo "Your Passwords do not match."; echo '<meta content="0; URL=../signup.php" http-equiv="Refresh" />'; } ?> Quote Link to comment Share on other sites More sharing options...
thesaleboat Posted July 30, 2008 Author Share Posted July 30, 2008 Thanks guys that helped alot, especially the redirect thank you. But for some reason it always says the passwords do not match?! ??? they are the same when i type them in any ideas? Quote Link to comment Share on other sites More sharing options...
revraz Posted July 30, 2008 Share Posted July 30, 2008 echo both $password and $password_again to verify. Quote Link to comment Share on other sites More sharing options...
dubc07 Posted July 30, 2008 Share Posted July 30, 2008 This should help the error listing after success <?php include('config.php'); require_once("functions.php"); $tbl_name=users; // values sent from form $name=$_POST['name']; $email=$_POST['email']; $password=$_POST['password']; $password_again=$_POST['password_again']; // Insert data into database if ($password == $password_again) { $sql="INSERT INTO $tbl_name (name, email, password) VALUES ('$name', '$email', '$password')"; $_SESSION["name"] = $name; $_SESSION["password"] = $password; $result=mysql_query($sql); redirect_to("login_success.php"); } exit; else { echo "Your Passwords do not match."; echo '<meta content="0; URL=../signup.php" http-equiv="Refresh" />'; } ?> I Just inserted an exit statement which is good practice if your programing php or any language. This stops the script from going ahead. Quote Link to comment Share on other sites More sharing options...
thesaleboat Posted July 30, 2008 Author Share Posted July 30, 2008 Thanks so much guys... I really like that: echo '<meta content="3; URL=signup.php" http-equiv="Refresh" />'; here is my working code, the echo was an awsome idea I need to remember to do that its so simple. here is my now working code thanks to you guys: <?php require_once("functions.php"); include('dbconnect.php'); $tbl_name="users"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $tbl_name=users; // values sent from form $myusername=$_POST['myusername']; $email=$_POST['email']; $mypassword=$_POST['mypassword']; $password_again=$_POST['password_again']; // Insert data into database if ($mypassword == $password_again) { $sql="INSERT INTO $tbl_name (name, email, password) VALUES ('$myusername', '$email', '$mypassword')"; $_SESSION["myusername"] = $myusername; $_SESSION["mypassword"] = $mypassword; $result=mysql_query($sql); redirect_to("login_success.php"); } else { echo "Your Passwords do not match."; echo '<meta content="3; URL=signup.php" http-equiv="Refresh" />'; //redirect_to("signup.php"); //header("location:signup.php"); } ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted July 30, 2008 Share Posted July 30, 2008 Glad you got it working. Quote Link to comment Share on other sites More sharing options...
thesaleboat Posted July 30, 2008 Author Share Posted July 30, 2008 how do you add code in that sweet window lol? Quote Link to comment Share on other sites More sharing options...
revraz Posted July 30, 2008 Share Posted July 30, 2008 Use code or php tags [code] [code=php:0] [/code] Quote Link to comment 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.