0

I'm very new to PDO. The issue I'm currently facing is that I'm trying to grab a users first name from a column however I have no idea how to fetch it properly. I've managed to find verify the user email with the email in the database now I just need to fetch the UserFirstName column and store it in a variable.

$data = array();
 if(isset($_POST['email'])){
  $data = $_POST['email'];


            if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) {
                $data = $_POST['email'];

            $stmt = $pdo->prepare('SELECT * FROM users WHERE UserEmail = :UserEmail');
                $stmt->execute(array(':UserEmail' => $data));
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
jake
  • 3
  • 3

1 Answers1

-1

change query to:

$stmt = $pdo->prepare('SELECT UserFirstName FROM users WHERE UserEmail = :UserEmail');

To execute:

$stmt->execute(array(':UserEmail' => $data));

then to fetch single column

$result = $stmt ->fetchColumn();
print("name = $result\n");

for reference http://php.net/manual/en/pdostatement.fetchcolumn.php

Imran Qamer
  • 2,253
  • 3
  • 29
  • 52
  • It returns Invalid parameter number: no parameters were bound in "$result = $stmt ->fetchColumn();" – jake Jan 16 '17 at 16:03
  • That's because you need to bind the parameters, use the execute you already had in the question: `$stmt->execute(array(':UserEmail' => $data));` – Qirel Jan 16 '17 at 16:04
  • 1
    Oh I see now! Thank you for clearing that up and taking your time! – jake Jan 16 '17 at 16:08