-1

I am making a web application in PHP, but for some reason does $count return nothing. I have tried to see if it echos an int but it does not.

Here is my code:

$query = $pdo->prepare("SELECT COUNT('user_id') FROM 'users' WHERE 'user_name' = '$username' AND WHERE 'password' ='$password'");
    $query->execute();
    $count = $query->fetchColumn();
    ;
    if($count==1){
       $_session['username'] =$username;
        $_session['logged_in'] =true;
  header('location: addfile.php');


    }else{
        echo "<p> gegevens kloppen niet</p>";
        echo "<p>$count</p>";
    }

    if(empty($username) || empty($password)){

        $error = true;

    }
halfer
  • 19,824
  • 17
  • 99
  • 186
  • You are misusing single quotes (`'`). You should not have them around the column names or table name. Also, you can have only one `WHERE` clause. The syntax is `WHERE x AND y`, not `WHERE x AND WHERE y`. Turning on error reporting would have revealed these basic errors. – elixenide May 24 '15 at 08:40

1 Answers1

-1

Try $count = $query->rowCount() I've had the same issue in the past and rowCount works where fetchColumn doesn't. I'm not entirely sure on the query you have also. You might have to change it to

SELECT id FROM users WHERE username = $username and password = $password
Morgan Green
  • 1,012
  • 2
  • 10
  • 22