Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
713 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 Answer

0 votes
by (71.8m points)

Remove single quotes ' :

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...