1

i'm seriously facing the problem of: Cannot modify header information header already started by out put at ...

<?php 
if ($_POST)
{
$counter = 0;

$Role = $_POST['urole'];
$Username = $_POST['uname'];
$Userid = $_POST['password'];

// validating field values

if($Role == "Select Role" || strlen($Username)<=0 || strlen($Userid)<=0)
{
$counter = 1;

echo "<center><font color=red><h3>"."Please, Provide values for all the fields"."</h3></font></center>";

exit;
}

$dbconnect = mysql_connect('localhost','root','');

if (!$dbconnect)

    {
    die ('could not connect:'.mysql_error());
    }
 $selectdb = mysql_select_db('UGI', $dbconnect);

 $query = "select EmployeeLoginType, EmployeeUserName, EmployeePassword from EmployeeCredentials where EmployeeLoginType='".$_POST['urole']."' and EmployeeUserName='".$_POST['uname']."' and EmployeePassword='".$_POST['password']."'";

 $dbquary = mysql_query($query, $dbconnect);

if (!$dbquary)
    {
    echo "No Record Found:".  mysql_error();
    }  
    else 
        {
        $rowfetch = mysql_fetch_array($dbquary);
        }
if (!$rowfetch)
    {
    echo ("<font color='red' size='+2'>Invalid Login Credentials</font>");
    }
    else {
              //      $username = $_POST['uname'];
                    $_SESSION['uname'] = $Username;
                    $role = $rowfetch[0];
                    $name = $rowfetch[1];
                    $password = $rowfetch[2];
         }
         if (strcasecmp($role, "Manager") === 0 && $name === "Bello" && $Userid === "smile2me")
         {
                        header('Location:PeopleManagement.php');
                      exit();    
         }


        /* else if 

                        (strcasecmp ($role, 'Assistant Manager') == 0 && $name == 'Ismail' && $Userid == $password)
                       header("Location:EditEmployeeDetails.php");

                    else if

                        (strcasecmp($role, 'Employee') == 0 && $Username ==$name  && $Userid == $password)
                        header("Location:Admin.php");


                    */

}enter code here
 // echo "<font color='red'><h3><em>Invalid Login credentials: Try again</em></h3></font>";
SuperDJ
  • 7,488
  • 11
  • 40
  • 74
Smile
  • 11
  • 2
  • Dude. Check if your variables are set prior to trying to access them. `$Role = isset($_POST['urole']) ? $_POST['urole'] : false;`. – Ohgodwhy Nov 14 '15 at 19:58

1 Answers1

1

header() must be called before any echo.

Nick
  • 9,735
  • 7
  • 59
  • 89