PDO not binding placeholders

元气小坏坏 提交于 2019-12-24 04:18:46

问题


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.


回答1:


Remove single quotes ' :

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



回答2:


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.



来源:https://stackoverflow.com/questions/20496805/pdo-not-binding-placeholders

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!