Page 1 of 1

header function not working: generates error

Posted: Sun Dec 06, 2009 12:12 pm
by mianmajidali
hi to all,
i m using header to call the file data.php on successful login, but it generates a error
"Warning: Cannot modify header information - headers already sent by (output started at /home3/oscobizz/public_html/login.php:9) in /home3/oscobizz/public_html/login.php on line 86
"
....."line 86 has header function"
----------------------------------------------
this is the file code login.php
----------------------------------------------
<?php
if(isset($_POST['submit']))
{
$con = mysql_connect("localhost","oscobizz_osadmin","os-co123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("oscobizz_os", $con);
$chk = mysql_query("select * from members where name='".$_POST['name']."' and pass='".$_POST['pass']."'");
if(mysql_num_rows($chk)>0)
{
session_register('s_id');
$_SESSION['s_id']=1122;
header("Location:/data.php");
}
else
{
echo "Wrong Username or Password:";
unset($_SESSION['s_id']);
}
} //end of submit if
?>

---------------------------------------------------
what should i do ???

Re: header function not working: generates error

Posted: Sun Dec 06, 2009 2:12 pm
by AbraCadaver
You can't output anything before a header call, so evidently you have a blank line before your <?php tag, or you are including this file from another and it has already outputted something.

-Shawn

Re: header function not working: generates error

Posted: Sun Dec 06, 2009 2:23 pm
by mianmajidali
this is all the file i m using...i think there is no blank line before <? tag
---------------
<tr>
<form name="Login" method="post" action="" enctype="multipart/form-data">
<td colspan="7" class="ind-content" valign="top" height="400">
<table width="100%" border="0" cellpadding="3" cellspacing="1">
<tr>
<td colspan="3">&nbsp;</td>
</tr>

<tr>
<td colspan="3" ><strong>Member Login </strong></td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">&nbsp;</td>
<td width="294"><input name="name" type="text" id="name"></td>
</tr>
<tr>
<td>Password</td>
<td>&nbsp;</td>
<td><input name="pass" type="password" id="pass"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="submit" value="Login"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>
<?php
if(isset($_POST['submit']))
{
$con = mysql_connect("localhost","oscobizz_osadmin","os-co123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("oscobizz_os", $con);
$chk = mysql_query("select * from members where name='".$_POST['name']."' and pass='".$_POST['pass']."'");
if(mysql_num_rows($chk)>0)
{
session_register('s_id');
$_SESSION['s_id']=1122;
header("location: /data.php");
}
else
{
echo "Wrong Username or Password:";
unset($_SESSION['s_id']);
}
} //end of submit if
?>
</td>
</tr>
</table>

</td>
</form>
</tr>

Re: header function not working: generates error

Posted: Sun Dec 06, 2009 2:26 pm
by mianmajidali
i have now removed even HTML coding blank lines, now there is no blank line...but header not working....

Re: header function not working: generates error

Posted: Sun Dec 06, 2009 4:27 pm
by AbraCadaver
You can't output anything. None of that HTML before the <?php tag can be there.

-Shawn