I get this error when I run the code below. I have normally used the msql functions butI have tried to get to use the PDO instead. What is wrong ?
Fatal error: Non-static method PDO::query() cannot be called statically on line 14
<?php
if(isset($_POST['username']) AND isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$password_hash = md5($password);
if (!empty($username) AND !empty($password) ) {
$query = "SELECT 'id' FROM `userdatabase` WHERE 'email'='$username' AND 'password'='$password_hash'";
if($query_run = PDO::query($query)){
$query_num_rows = PDO::rowcount($query_run);
if ($query_num_rows==0){
echo 'invalid password/username';
} else {
echo 'Username/password = correct';
}
}
} else {
echo 'You must enter a password..';
}
}
?>
::sign is used to call methods that are defined as static, which means you don’t need to create instance of an object to call this method.query()method is not static which means that you need to createPDOobject first and then callquery()method on that object.This should look like this: