简体   繁体   中英

PDO not binding placeholders

I am trying to change my log in script from mysql to PDO . For the rest of my script all seams to be going well apart from this parts and I simply cant see why.

I have the below code

...
$pasword=md5($_POST['password']);
$email=$_POST['email'];

....

$query ="SELECT id FROM guests WHERE email=':eml' AND password =':pwd' AND lead_guest=17";
// $param2=array(':eml'=>$email,':pwd'=>$pasword);
$state=$dbh->prepare($query);
$state->bindParam(':eml',$email);
$state->bindParam(':pwd',$pasword);
$state->execute();

in it's current state it will return a row count of 0 (which it should not), I have also tried

  //$state->bindParam(':eml',$email);
  //$state->bindParam(':pwd',$pasword);
  $state->execute($param2);

which also returns a row count of 0.

The variables $email and $pasword are correct when I echo them out, and the script works perfectly using mysql_ functions.

The $dbh variable is in created in a header and with a $query ="select id where 1" it works as expected.

I am sure (although could be wrong ) that I have the problem narrowed down to the state->bindParam() part of the script. I am completely lost why this part of the script is not working any advice warmly welcome.

删除单引号 '

SELECT id FROM guests WHERE email=:eml AND password =:pwd

Your query will be

$query ="SELECT id FROM guests WHERE email=:eml AND password =:pwd AND lead_guest=17";

No single quotes around :eml and :pwd .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM