Jump to content

[SOLVED] User Registration Redirect Problem


thesaleboat

Recommended Posts

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

}

 

?>

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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" />';
}

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

}

?>

Link to comment
Share on other sites

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.