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

}

 

?>

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

 

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.

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

?>

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.

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

}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.