-1

I know this question is already on the questions list. I tried everyone's answer but it is not helping me a little bit. The header function is working fine on localhost but when I upload the files to the server the header line is not working. I am tired of doing changes again and again. I need your help. Please!

<?php 
    session_start();    
    $name = $_POST['Username'];
    $pass = $_POST['Password'];
    if(isset($_POST['Submit'])){
    if((isset($name) && isset($pass))){

    include 'connection.php';

    $sql = "select * from `users` where username='$name' AND password='$pass' ";
    $result = mysqli_query($conn, $sql); 

    if(mysqli_num_rows($result) > 0){
        while($row = mysqli_fetch_assoc($result)) {
        $_SESSION['login_user'] = $row["username"];
        $_SESSION['login_user_pass'] = $row["password"];

        header('Location: ../php/businesshome.php'); // Redirecting To Other Page
    }   
        }
         else {
            $error = "Username or Password is invalid";
        } 
    }
}
    mysqli_close($conn);
?>
Amit Basliyal
  • 840
  • 1
  • 10
  • 28
ZIA JAPPA
  • 25
  • 1
  • 12
  • Doesn't work how? Please be more specific. Have you turned on error reporting? Checked your logs? Also, you are wide open to [**SQL injection**](https://www.owasp.org/index.php/SQL_Injection). – elixenide Dec 05 '15 at 04:09
  • Either your query failed and/or you're outputting before header. Error reporting on PHP and checking on the SQL will tell you that. You're not doing that. Refs: http://php.net/manual/en/function.error-reporting.php and http://php.net/manual/en/mysqli.error.php and http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php – Funk Forty Niner Dec 05 '15 at 04:22

1 Answers1

0

Finally I get the answer. There was a space in header('Location: ../php/businesshome.php');. After elimination of space it is working fine.

ZIA JAPPA
  • 25
  • 1
  • 12