Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MythicFrost

macrumors 68040
Original poster
Mar 11, 2009
3,944
40
Australia
Hi, I'm trying to redirect my page after I'm done, this is at the very end of my code:
PHP:
header('Location: signupcomplete.php');

It doesn't do anything though.

Anyone know why?

Kind Regards
 
I think I'm not doing that, this is my code, I think you can see what I'm trying to do.

PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Sign Up</title>
</head>

<body>
<script type="text/javascript">

</script>
<?php require_once('menu.php'); ?> //this has my banner/home/signup buttons on it
<?php
//use $_SESSION to store error information
$username = mysql_real_escape_string($_POST["tfUsername"]);
$password = mysql_real_escape_string($_POST["tfPassword"]);
$passwordConfirm = mysql_real_escape_string($_POST["tfPasswordConfirm"]);
$email = mysql_real_escape_string($_POST["tfEmail"]);
$emailConfirm = mysql_real_escape_string($_POST["tfEmailConfirm"]);
$country = mysql_real_escape_string($_POST["sCountry"]);
$bUsernameTaken=false;
$bPwNotPwCon=($password == $passwordConfirm);
$bEmNotEmCon=($email == $emailConfirm);

$mysqlCon = mysql_connect("localhost", "priv", "priv");
if (!$mysqlCon)
{
	die("Unable to connect, ".mysql_error());
}
mysql_select_db("main", $mysqlCon);

$query = sprintf("SELECT * FROM Users WHERE username = '%s'", mysql_real_escape_string($username));
$result = mysql_query($query, $mysqlCon);

$iNumRows = mysql_num_rows($result);
if ($iNumRows > 0)
{
	$bUsernameTaken=true;
}
mysql_close($mysqlCon);
$bContinue = !$bUsernameTaken && !$bPwNotPwCon && !$bEmNotEmCon;
?>
<form id="form1" name="form1" method="post" action="signup.php">
    <table width="600" border="0" align="center">
        <tr>
            <td height="114" colspan="3">     <hr /></td>
        </tr>
        <tr>
            <td width="89">Username</td>
            <td width="269" valign="middle"><input name="tfUsername" type="text" id="tfUsername" value="username" maxlength="30" />
         	</td>
        </tr>
        <tr>
            <td></td>
            <td valign="middle">
            </td>
        </tr>
        <tr>
            <td>Password</td>
            <td colspan="2"><input name="tfPassword" type="password" id="tfPassword" value="password" maxlength="20" /></td>
        </tr>
        <tr>
            <td height="20">Confirm</td>
            <td height="20" colspan="2"><input name="tfPasswordConfirm" type="password" id="tfPasswordConfirm" value="passwordconfirm" maxlength="20" /></td>
        </tr>
        <tr>
            <td height="20"> </td>
            <td valign="middle">
            </td>
        </tr>
        <tr>
            <td height="20">E-mail</td>
            <td height="20" colspan="2"><input name="tfEmail" type="text" id="tfEmail" value="email" maxlength="90" /></td>
        </tr>
        <tr>
            <td height="20">Confirm</td>
            <td height="20" colspan="2"><input name="tfEmailConfirm" type="text" id="tfEmailConfirm" value="emailconfirm" maxlength="90" /></td>
        </tr>
        <tr>
            <td height="20"> </td>
            <td valign="middle">
            </td>
        </tr>
        <tr>
            <td height="20">Country</td>
            <td height="20" colspan="2" valign="middle"><select name="sCountry" id="sCountry">
                <option>Select an option</option>
                <option>Australia</option>
                <option>France</option>
                <option>Japan</option>
                <option>America</option>
            </select></td>
        </tr>
        <tr>
            <td colspan="3" align="right"><label><!-- type=submit -->
            </label>
            <hr /></td>
        </tr>
    </table>
    <table width="600" border="0" align="center">
        <tr>
        	<td width="192"></td>
            <td width="252"><div align="right">
                <input type="submit" name="bSignup" id="bSignup" value="Signup" />
            </div></td>
        </tr>
    </table>
</form>
<?php
if ($bContinue)
{
	$mysqlCon = mysql_connect("localhost", "root", "root");
	if (!$mysqlCon)
	{
		die("Unable to connect, ".mysql_error());
	}
	mysql_select_db("main", $mysqlCon);

	$sqlQuery = "INSERT INTO Users (id,username, password, email, country) VALUES ('0','$username','$password','$email', '$country')";
	$queryResult = mysql_query($sqlQuery, $mysqlCon);
	if (!$queryResult)
	{
		die("Error, ".mysql_error());
	}
	header('Location: signupcomplete.php'); //this doesn't seem to work
	mysql_close($mysqlCon);
}
?>
</body>
</html>

Any idea?

Kind Regards
 
Yup, as I said, you're using it after you outputted things to the screen. All that HTML at the top, that output. Can't do it that way.
 
Alright, I'm doing that, no success, is "Location: signupcomplete.php" correct, will it know to look in the root folder for it?

This is at the VERY top of my code, all HTML is below it.

PHP:
<?php
//use $_SESSION to store error information
$username = mysql_real_escape_string($_POST["tfUsername"]);
$password = mysql_real_escape_string($_POST["tfPassword"]);
$passwordConfirm = mysql_real_escape_string($_POST["tfPasswordConfirm"]);
$email = mysql_real_escape_string($_POST["tfEmail"]);
$emailConfirm = mysql_real_escape_string($_POST["tfEmailConfirm"]);
$country = mysql_real_escape_string($_POST["sCountry"]);
$bBlank=false;
$bUsernameTaken=false;
if ($username == "")
{
	$bBlank=true;
}
$bPwNotPwCon=!($password == $passwordConfirm);
$bEmNotEmCon=!($email == $emailConfirm);
//Styles
/*function getStyle()
{
	$styleFont="arial";
	$styleColor="red";
	$styleFontSize="11";
	$s = "<p style=\"font-family:".$styleFont."; color:".$styleColor."; font-size:".$styleFontSize."px\">";
	return $s;
}
$sUserTaken = getStyle()."That username is already taken</p>";
$sPwNotPwCon = getStyle()."Your password and confirm password do not match</p>";
$sEmNotEmCon = getStyle()."Your email and confirm email do not match</p>";*/
//End Styles
$mysqlCon = mysql_connect("localhost", "root", "root");
if (!$mysqlCon)
{
	die("Unable to connect, ".mysql_error());
}
mysql_select_db("main", $mysqlCon);

$query = sprintf("SELECT * FROM Users WHERE username = '%s'", mysql_real_escape_string($username));
$result = mysql_query($query, $mysqlCon);

$iNumRows = mysql_num_rows($result);
if ($iNumRows > 0)
{
	$bUsernameTaken=true;
}
$bContinue = !$bUsernameTaken and !$bPwNotPwCon and !$bEmNotEmCon and !bBlank;
//echo (sprintf("bCon %b, bUser %b, bPwNotPwon %b, bEmNotEmCon %b, bBlank %b", $bContinue, !$bUsernameTaken, !$bPwNotPwCon, !$bEmNotEmCon, !$bBlank));
if ($bContinue)
{
	$sqlQuery = sprintf("INSERT INTO Users (id,username, password, email, country) VALUES ('%s','%s','%s','%s', '%s')", 0, mysql_real_escape_string($username), mysql_real_escape_string($password), mysql_real_escape_string($email), mysql_real_escape_string($country));
	$queryResult = mysql_query($sqlQuery, $mysqlCon);
	if (!$queryResult)
	{
		die("Error, ".mysql_error());
	}
	header('Location: signupcomplete.php'); 
}
mysql_close($mysqlCon);
?>

I can't see any output there

Kind Regards
 
Alright, I'm doing that, no success, is "Location: signupcomplete.php" correct, will it know to look in the root folder for it?

No, it'll need the full URL

PHP:
header('Location: '. $_SERVER['DOCUMENT_ROOT'] .'/signupcomplete.php');
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.