0

I have the following code:

$selectUserQuery = 'SELECT email_address, password FROM user WHERE email_address = :email_address AND password = :password';
$prepSelectUser = $conn->prepare($selectUserQuery);
/*
* HOW DO I ADD MULTIPLE PARAMETERS TO THIS BINDPARAM() FUNCTION?
*/
$prepSelectUser->bindParam(':email_address', $email, PDO::PARAM_INT);
$prepSelectUser->execute();
$userResult = $prepSelectUser->fetchAll();
$userCount = count($userResult);

How can I add multiple parameters to the bindParam() function?

2
  • Oops, yeah, mistake. It doesn't cause any trouble though? Commented Mar 28, 2014 at 12:14
  • You just call bindParam() once for each parameter you wish to bind Commented Mar 28, 2014 at 12:14

2 Answers 2

6

You don't actually need this function at all. as well as most of other code you used.

$sql  = 'SELECT 1 FROM user WHERE email_address = ? AND password = ?';
$stmt = $conn->prepare($sql);
$stmt->execute([$email, $password]);
$userCount = $stmt->fetchColumn();
Sign up to request clarification or add additional context in comments.

Comments

1

First, change

$prepSelectUser->bindParam(':email_address', $email, PDO::PARAM_INT);

to

$prepSelectUser->bindParam(':email_address', $email, PDO::PARAM_STR);

then call another bindParam, like

$prepSelectUser->bindParam(':password', $password, PDO::PARAM_STR);

1 Comment

Okay, yeah I noticed the mistake. I made it because I had copied this code from another website and didn't really understand PDO (it looks like Arabic at the beginning :D). I fixed it, changed it into STR. So basically, I just need to add a second bindParam() function to get this to work? Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.