Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
660 views
in Technique[技术] by (71.8m points)

php - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Remove single quotes ' :

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...