-1

instead of taking me to the successful page it stops at the script page and gives me the error in the title "Warning: Cannot modify header information - headers already sent by (output started at" i believe it has something to do with the header and having it after the echo's or something but i have no idea on how to fix it. any help greatly appreciated

   <div style="position:absolute;left:750px;top:0px;width:160px;height:41px;overflow:hidden;">
<?php
if(isset($_SESSION['userName'])){
echo 'You are already logged in as <a href="recent.php" <a>'.$_SESSION['userName'].'</a>. Not you? <a href ="logout.php"</a>logout';
}else{
echo ' Please login <a href ="login_form.php" <a> click here</a>'.' Register <a href="register.php"<a>here</a>';
}

?>  
</div>
<div style="position:absolute;left:400px;top:150px;width:400px;height:141px;overflow:hidden;">
<?php
//=============Configuring Server and Database=======
$host        =    'localhost';
$user        =    'root';
$password    =    'revilo';
//=============Data Base Information=================
$database    =    'dbsneaker';

$conn        =    mysql_connect($host,$user,$password) or die('Server Information is not Correct'); //Establish Connection with Server
 mysql_select_db($database,$conn) or die('Database Information is not correct');

 //===============End Server Configuration============

 //=============Starting Registration Script==========

 $userName    =    mysql_real_escape_string($_POST['txtUser']);

 $password    =    mysql_real_escape_string($_POST['txtPassword']);

 //=============To Encrypt Password===================
//$password    =    md5($password);
//============New Variable of Password is Now with an Encrypted Value========
if(!trim($userName) || !trim($password)){
echo 'Please fill in the form <br> <a href="register.php"<a>Click here</a> to return to registration';
}else{
// There's no empty field
// Check user exists
$checkQuerySql = "SELECT * FROM `bladmin` WHERE `admin_usr_name` = '$userName'";
$checkQuery = mysql_query($checkQuerySql);
if(mysql_fetch_assoc($checkQuery)){
    echo 'User already exists <br> <a href="register.php"<a>Click here</a> to return to registration';
   }else{
    if(isset($_POST['btnRegister'])) //===When I will Set the Button to 1 or Press Button to register
{
$query    =    "insert into bladmin(admin_usr_name,admin_pwd)values('$userName','$password')";
$res    =    mysql_query($query);
header('location:success_register.php');
}// User doesnt exists
}
}



?>
</div>
</div>

2 Answers2

0

header

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

Therefore you need to reorganize your code in a way that you call header before output anything.

peterm
  • 91,357
  • 15
  • 148
  • 157
0

Answer to your question is simple, there should be NO output before you set your headers; this is a common mistake to newbies who haven't really used headers.

<?php
header ("Location: test.php");
?>

this wont throw an error

<?php
 echo "blabla";
header ("Location: test.php");
?>

OR

<strong> test</strong>
<?php
header ("Location: test.php");
?>

the above will trigger an error.

Daryl Gill
  • 5,464
  • 9
  • 36
  • 69