Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Integrating PHP with Databases Using Relational Tables Using a Prepared Statement

Jorge Torres
Jorge Torres
930 Points

Error on your validation

This is my code: function get_member($id) { include("connection.php");

try {
  $results = $db->prepare(
      "SELECT member_id, email, fullname, level
      FROM members
      WHERE member_id = ?"
  );
  $results->bindParam(1, $id, PDO::PARAM_INT);
  $results->execute();     
} catch (Exception $e) {
  echo "bad query";
}

$members = $results->fetch();
return $members;

}

The system is saying that I need to use a where clause... there is the where clause and it not allow me to go to the next task. Please verify your system.

index.php
<?php
function get_member($id) {
    include("connection.php");

    try {
      $results = $db->prepare(
          "SELECT member_id, email, fullname, level
          FROM members
          WHERE member_id = ?"
      );
      $results->bindParam(1, $id, PDO::PARAM_INT);
      $results->execute();     
    } catch (Exception $e) {
      echo "bad query";
    }

    $members = $results->fetch();
    return $members;
}

1 Answer

Hi Jorge,

The original code was using the fetchAll method on the second to last line and you changed it to the fetch method.

You should pass once you change that back. The rest of your code is correct.