3

After user login into database, he should be redirected to index.php, but all I get is warning message: "Cannot modify header information - headers already sent by (output started at..."

This is my input form:

<form action="login.php" method="post">
<div id="header"><h2 class="sansserif">Login</h2></div>
<table>

    <tr>
        <td>Enter Username:</td>
        <td> <input type="text" name="username" size="20"></td>
    </tr>

    <tr>
        <td>Enter Password:</td>
        <td><input type="password" name="password" size="20"></td>
    </tr>
    <tr>
         <td><input type="submit" value="Log In"></td>
         <td><a href="signup.html">Sign Up</a></td>
   </tr>
 </table>
</form>

This is my code:

<?php 
include("configuration.php"); 
$username = $_POST["username"];
$password = $_POST["password"];
$match = "select id from $table where username = '".$_POST['username']."'and password =         '".$_POST['password']."';"; 
$qry = mysql_query($match);
$num_rows = mysql_num_rows($qry); 
if ($num_rows <= 0) { 
echo "Sorry, there is no username $username with the specified password.";
echo "Try again";
exit; 
} else {
$_SESSION['user']= $_POST["username"];
header("Location:index.php");
}?>
strellson
  • 125
  • 1
  • 2
  • 12

2 Answers2

0

Check that you have no whitespace before or after your PHP tags. I can see 3 spaces at the start which could be causing"cannot modify header information".

Space
  • 2,022
  • 1
  • 19
  • 29
0

first try commenting header() function check if there is any output on the browser. If nothing check your configuration.php maybe something is being echoed or printed.

Abhishek Salian
  • 928
  • 2
  • 10
  • 27