Header problem please help

hi I’m trying to redirect my page to another page after a user registers. but every time the user registers, it inputs the detail to the database but it doesn’t allow them to register. it is doing this to every header statement I have on each page on my website.

I was told it’s because of an echo (html) before the header, I’m new to all this so please can anyone help me

thank you

this is the code to my register page:
[php]
<?php

error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
 
<?php

 
// Connect to the MySQL database
include "../storescripts/connect_to_mysql.php";
 
 
//This code runs if the form has been submitted
 
if (isset($_POST['submit'])) {
 
 
 
//This makes sure they did not leave any fields blank
 
if (!$_POST['firstname'] | !$_POST['surname'] | !$_POST['address1'] | !$_POST['postcode'] | !$_POST['phonenumber'] | !$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] | !$_POST['email'] ) {

header(“location: register_user_fail.php”);
exit();

}
 
 
 
// checks if the username is in use
 
if (!get_magic_quotes_gpc()) {
 
$_POST['username'] = addslashes($_POST['username']);
 
}
 
$usercheck = $_POST['username'];
 
$check = mysql_query("SELECT username FROM user WHERE username = '$usercheck'")
 
or die(mysql_error());
 
$check2 = mysql_num_rows($check);
 
 
 
//if the name exists it gives an error
 
if ($check2 != 0) {
 
 header("location: username_is_used.php");

exit();

} 
 
 
// this makes sure both passwords entered match
 
if ($_POST['pass'] != $_POST['pass2']) {

header(“location: password_don’t_match.php”);
exit();

}
 
 
 
 
 
// now we insert it into the database
 
$insert = "INSERT INTO user (firstname, surname, address1, address2, postcode, phonenumber, username, password, email)
 
VALUES ('".$_POST['firstname']."', '".$_POST['surname']."', '".$_POST['address1']."', '".$_POST['address2']."', '".$_POST['postcode']."',  '".$_POST['phonenumber']."', '".$_POST['username']."', '".$_POST['pass']."', '".$_POST['email']."')";

$add_member = mysql_query($insert);
if (!$add_member) echo “$insert
”.mysql_error();
?>

 <?php
  header("location: register_success.php");

exit(); ?>

<?php
}
 
else
{
?>
 
<!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>User Register</title>
<link rel="stylesheet" href="../style/style.css" type="text/css" media="screen" />
</head>
<body>
<div align="center" id="wrapper">
<?php include_once("user_login_template_header.php");?>
<div id="content">
<table width="100%" border="0" cellspacing="0" cellpadding="10">
<tr>
<td width="32%" valign="top">
</td>
<td width="35%" valign="top">
 
 
 
 
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
 
<table border="0">
First Name:
<input type="text" name="firstname" maxlength="60">
 
</td></tr>
Surname:
<input type="text" name="surname" maxlength="60">
 
</td></tr>
Address 1:
<input type="text" name="address1" maxlength="60">
 
</td></tr>
Address 2:
<input type="text" name="address2" maxlength="60">
 
</td></tr>
Postcode:
<input type="text" name="postcode" maxlength="9">
 
</td></tr>
Telephone Number:
<input type="text" name="phonenumber" maxlength="12">
 
</td></tr>



<tr><td>Username:</td><td>
 
<input type="text" name="username" maxlength="60">
 
</td></tr>
 
<tr><td>Password:</td><td>
 
<input type="password" name="pass" maxlength="25">
 
</td></tr>
 
<tr><td>Confirm Password:</td><td>
 
<input type="password" name="pass2" maxlength="25">
 
</td></tr>
Email:
<input type="email" name="email" maxlength="60">
 
</td></tr>
<tr><th colspan=2><input type="submit" name="submit"
value="Register"></th></tr> </table>
 
</form>
 
 
 
<br />
</p>
<p><br />
</p></td>
<td width="33%" valign="top">
</td>
</tr>
</table>
 
</div>
<?php include_once("../footer.php");?>
</div>
</body>
</html>
<?php
 
}
?>[/php]

It seems to work for me (I had to comment out the references and the SQL queries). However, have a look at this section of your code. Lines 73 - 80… First your exiting and entering php a lot when you do not need to like here why exit php ?> after the exit(); statement? your next piece of code is just more php so you have to open php again. Also this if then statement is formatted strangely best I can tell try my version…

Yours:
[php]
$add_member = mysql_query($insert);
if (!$add_member) echo “$insert
”.mysql_error();

  header("location: register_success.php");

exit(); ?>

<?php

[/php]

Mine:

[php] $add_member = mysql_query($insert);
if (!$add_member) {
echo “$insert
”.mysql_error();
} else {
header(“location: register_success.php”);
exit();
}
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service