hi i am new to php. i am getting the following error.

------Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\login\login.php:23)-----------


<html>
<body>
<form action="login.php" method="post">
<div>
<table width="100%">
<tr>
<td><img src="Logofinalcopy.gif"></td>
</tr>
<tr>
<td bgcolor="aqua"><h2>Login</h2></td>
</tr></table>
<table align="right" style="width:40%">
<br>
<tr>
<td>username:</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>password:</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td align="CENTER" COLSPAN="4">
<input TYPE="SUBMIT" name="submit" value="Login">
<input TYPE="reset" name="submit" value="clear"></td>
</tr>
</table>
</div>
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
{
 $con = mysql_connect("10.70.1.50","invensis","invensis");
 if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
  $con= mysql_select_db("Login",$con);
  if (!$con)
  {
  die('Could not connect DB: ' . mysql_error());
  }
  $sql="SELECT * FROM users WHERE username='invensis' AND password='invensis'";
  $result=mysql_query($sql); 
  $count= mysql_num_rows($result);
  echo $count;
  if($count==1)
  {
            $sql = mysql_query("SELECT role FROM users WHERE username='invensis' AND password='invensis'");
            while($info = mysql_fetch_array($sql))
            {
                if($info['role']=='0')
                {
                    header('location: [url]http://localhost//login/test.php');[/url]
                }
                else 
                {
                    echo 'null';
                }
            } 
  }             
} 

You cannot send any output to the browser before using the header() function. So put all the html content and your echo statements in your code after the header() function.
If you still want to use the browser output before the header(), then you need to do something like this..

<?php 
ob_start();
?>
<html>
<body>
Testing!
</body>
</html>
<?php 
$x = 0;
if ($x == 1) {
	header("location:http://google.com");
} else {
	// do nothing but send the browser output.
	ob_end_flush();
}
?>

For more info on how the functions ob_start(), ob_end_flush() and header() works go through the following links.

http://in.php.net/manual/en/function.ob-start.php
http://in.php.net/manual/en/function.ob-end-flush.php
http://in.php.net/manual/en/function.header.php

thank u very much. now it is working.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.