-1

Please help me to fix this error this error

Warning: Cannot modify header information - headers already sent by (output started at /home/amberadv/public_html/admin/login.php:11) in /home/amberadv/public_html/admin/login.php on line 17

     <?php

session_start();

include_once('connect.php');

if(isset($_REQUEST['login']))

{

    $username=$_REQUEST['username'];

    $password=$_REQUEST['password'];

    $sql="select * from `admin` where `user`='$username' and `pass`='$password'";

    $result=mysql_query($sql);

    $records= mysql_fetch_array($result);

    print_r($records);

    //$count=mysql_num_rows($result);

    $_SESSION['user']=$username;    

    if($records['user']==$username && $records['pass']==$password)
    {
             //echo "in";
        header("Location:index.php");
    }

    else

    { 

    echo "out";

    print "Username And Password Incorrect";

    }

}

?> 
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
RiyazAhmed
  • 115
  • 1
  • 2
  • 10

2 Answers2

0

This can be happen majorly just because it may happen that due to

  • you are sending headers information which are already been sent
  • It may happen that you have started the session two times or multiple times in a page.

As you have provide the minimal information so try doing this

ob_clean

What it does?

This function discards the contents of the output buffer.

Jaymin
  • 1,643
  • 1
  • 18
  • 39
0

Problem is you are echo something before you do header("Location:index.php"); redirection

Check these cases

  • Remove the space before <?php tag
  • Remove all echo statements in connect.php and login.php
Thamaraiselvam
  • 6,961
  • 8
  • 45
  • 71