Page 1 of 1

Hosting PHP Problem

Posted: Sat Feb 28, 2009 3:35 pm
by fionaom87
Hey im trying to host a php files and i have a login linked with my db and the following error occurs

Warning: Cannot modify header information - headers already sent by (output started at D:\Domains\windowsanddoorscarraigtwohill.com\wwwroot\AdminLogin.php:1) in D:\Domains\windowsanddoorscarraigtwohill.com\wwwroot\AdminLogin.php on line 79


79 is the reports.php i have that hosted and everything in same file i dont understand why it wont work

Code: Select all

<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
 
<?php error_reporting (E_ALL ^ E_NOTICE); ?>
<html xmlns="http://www.w3.org/1999/xhtml">
 
<head>
   
     <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
 
     <title> Premier Windows and Doors ADMINISTRATION</title>
 
     <link rel="stylesheet" type="text/css" media="screen" href="style.css" />
 
</head>
<body>
   <div id="header">
<div id="logo">
    
 
<h1>Premier Windows and Doors</h1>
<h3> Carrigtwohill, Co.Cork </h3>
    
    </div>
           
           <div id="menu">
    
<ul>
            <li><a href="index2.html">Home</a></li>
            <li><a href="aboutus.html">About Us</a></li>
            <li><a href="select.php">Products</a></li>
            <li><a href="service.html">Services</a></li>
            <li><a href="contact.html">Contact Us</a></li>
</ul>
    </div>
    <!-- end #menu -->
</div>
   <div id="page">
   <div id="content">
 
<div id="box2">
<?php include 'config.php'; ?><!-- DB connection -->
 
<?php 
 
 
if (isset($_POST['login'])) {
 
 
 
    if(!$_POST['password']){ 
       $message='*Password is a required field!'.'<br/>';  
    }
    if(!$_POST['username']){
            
       $message='*Username is a required field!'.'<br/>';             
    }   
 
 
$check = mysql_query("SELECT * FROM login WHERE username = '".$_POST['username']."'")or die(mysql_error());
 
//checks if correct password is entered 
    while($info = mysql_fetch_array( $check )) 
    {
    $_POST['password'] = stripslashes($_POST['password']);
    $info['password'] = stripslashes($info['password']);
 
//gives error if the password is wrong
    if ($_POST['password'] != $info['password']) {
 
    $_SESSION['admin']=$_POST['username'];
        $message=$message.'*The password you entered is incorrect. Please try again!'.'<br/>';
         
    }//if
 
    else{
 
    header('Location: reports.php');
 
    }
     
    }//while
  print '<p class="error">'.'<img src="error.png" width="18" heigth="18" alt="Error"/>'.'Registration could not be completed due to the following errors:'.'<br />'.'</p>'.'<p class="error2">'.$message.'</p>'; 
  DisplayForm();
 
}//if
 
else
{
 
DisplayForm();
 
}
 
 
 
function DisplayForm()
{ 
 
?>
 
 
 
<form name="login-form" id="login-form" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> 
  
  <legend>Please login:</legend> 
  <hr>
  <dl> 
    <dt> 
      <label title="Username">Username:
      <input tabindex="1" accesskey="u" name="username" type="text" maxlength="50" id="username" /> 
      </label> 
    </dt> 
  </dl> 
  <dl> 
    <dt> 
      <label title="Password">Password:
      <input tabindex="2" accesskey="p" name="password" type="password" maxlength="15" id="password" /> 
      </label> 
    </dt> 
  </dl> 
  <dl> 
    <dt> 
    <hr>
      <label title="Submit"> 
      <input tabindex="3" accesskey="l" type="submit" name="login" value="Login" /> 
      </label> 
    </dt> 
  </dl> 
 
 
<?php
}
 
?>
</div>
</div>
</div>
<div id="footer">
 
    <p> Created by O'Mahony Web Design, Donoughmore, Co Cork Ireland 
    <br> Registered: 123456789 </p>
</div>
 
</body>
</html>
 
 
 
 
 
 
 
 
 
 
 
 

Re: Hosting PHP Problem

Posted: Sat Feb 28, 2009 3:56 pm
by Randwulf
The header() function cannot be used if output has already been sent to the browser. The HTML that you display before invoking the header() function is what's causing the problem.