Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I created my first member login form which takes the typical username and password and then sends it to the code below:

checklogin.php:

    mysql_connect($db_host, $db_username, $db_password) or die(mysql_error()); 
    mysql_select_db($db_database) or die(mysql_error());

    $username=$_POST['username'];
    $password=$_POST['password'];

    $username = stripslashes($username);
    $password = stripslashes($password);
    $username = mysql_real_escape_string($username);
    $password = mysql_real_escape_string($password);

    $sql="SELECT * FROM users WHERE username='$username' and password='$password'";
    $result=mysql_query($sql);

    $count=mysql_num_rows($result);
    if($count == 1) //ERROR APPEARS TO TAKE PLACE HERE
    {
        session_start();
        $_SESSION['username'] = $username;
        $_SESSION['password'] = $password;
        header('login_success.php');
    }
    else {
        header("location:login_fail.php");
    }

If I type in the wrong information everything works properly so I know the error appears to be taking effect in the marked if statement. I have been searching the internet now looking for solutions but none seem to match mine or I am overlooking them. I've made a few changes which brought me to this point, before I was receiving deprecation warnings.

Also, I have checked the logs and they are empty of errors relating to this.

share|improve this question

closed as off topic by Michael Hampton, MadHatter, Scott Pack, Ladadadada, SvW Oct 29 '12 at 23:51

Questions on Server Fault are expected to relate to professional server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

add comment

2 Answers

up vote 2 down vote accepted

change:

header('login_success.php');

to:

header('Location: login_success.php');

Also, session_start() is a common source of errors, often due to permissions.

Turn on error reporting with:

ini_set('display_errors', 1);
error_reporting(-1);
share|improve this answer
add comment

set display_errors=on in your php.ini. That way you can check what is wrong with your script.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.