Re: Warning: Cannot modify header information - headers already sent by (output sta
| From: | Henry Grech-Cini | Date: | Wed, 10 Mar 2004 11:51:27 +0000 |
| Subject: | Re: Warning: Cannot modify header information - headers already sent by (output sta | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-180005@lists.php.net to get a copy of this message | ||
Hi
The problem is that the header requires that no output
be generated by your script before it is invoked.
It makes this clear in the error message when it indicates
that on line 6 you produced output!
Try this instead (although the code seems a little confused).
<?php
session_start();
include_once("lib/lib_main.php");
dbConnect($host, $user, $pass);
$password = $_POST['password'];
$username = $_POST['username'];
$sql_login = mysql_query("SELECT id from user WHERE username='$username' and
password=password('$password')");
if(mysql_num_rows($sql_login)) {
header("Location: http://www.index.php");
}
echo "<FORM ACTION=\"$PHP_SELF\" METHOD=\"POST\">";
?>
<table align="center">
<tr><td>Username:</td><td> <input type="username"
name="username"></td></tr>
<tr><td>Password:</td><td> <input type="password"
name="password"></td></tr>
<tr><td></td><td align="center"><input type="submit"
name="submit"
value="Submit"></td><tr>
<?php echo "</FORM>"; ?>
"Mike Mapsnac" <mikerh9@hotmail.com> wrote in message
news:BAY15-F2692pkxR1CFE000065e1@hotmail.com...
> This code below gives me this error message:
> Warning: Cannot modify header information - headers already sent by
(output
> started at /var/www/html/account.php:6) in /var/www/html/account.php on
line
> 17
>
> The script check in the database if user exists and than redirect the page
> to the home index.php page. I know the problem exist in the header() ..
But
> I don't understand why?
>
>
>
> <?php
> session_start();
> include_once("lib/lib_main.php");
> dbConnect($host, $user, $pass);
>
> echo "<FORM ACTION=\"$PHP_SELF\" METHOD=\"POST\">";?>
> <table align="center">
> <tr><td>Username:</td><td> <input type="username"
> name="username"></td></tr>
> <tr><td>Password:</td><td> <input type="password"
> name="password"></td></tr>
> <tr><td></td><td align="center"><input
> type="submit" name="submit"
> value="Submit"></td><tr>
> <?php echo "</FORM>";
> $password = $_POST['password'];
> $username = $_POST['username'];
> $sql_login = mysql_query("SELECT id from user WHERE username='$username'
and
> password=password('$password')");
> if(mysql_num_rows($sql_login)) {
> header("Location: http://www.index.php");
> } ?>
>
> _________________________________________________________________
> Find things fast with the new MSN Toolbar - includes FREE pop-up blocking!
> http://clk.atdmt.com/AVE/go/onm00200414ave/direct/01/