Poula Adel Poula Adel - 2 months ago 8x
MySQL Question

MYSQL with PDO - Column not found

I'm using plain PHP with PDO for dealing with MySQL database, I'm developing a login system and when I try to verify matching database record this is my code:

$query = "SELECT id FROM users WHERE username=`:u` AND password=`:p`;";
$q = $db->prepare($query);
$q->bindParam(':u', $this->_username, PDO::PARAM_INT);
$q->bindParam(':p', $this->_passmd5, PDO::PARAM_INT);
if($q->execute()&& ($q->rowCount() == 1)){
return true;
return false;
}catch(PDOException $e){
$this->_errors[] = $e->getMessage();

when I submit the user name and password i.e. (admin/password). it gives me that error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column ''admin'' in 'where clause'


Try to remove the backticks around :u and :p from your select query. This type of backticks are for defining columns in mysql.