Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Robert Stamate
Robert Stamate
13,227 Points

I really don't get it.

I changed the query to prepare but the previous task becomes invalid. I don't understand why. Can I get a hint or a example that could help me get past it?

Thank you in advance.

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

    try {
      $results = $db->preprare(
          "SELECT member_id, email, fullname, level
          FROM members
          WHERE member_id = ". $member_id
      );
    } catch (Exception $e) {
      echo "bad query";
    }

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

3 Answers

Robert Stamate
Robert Stamate
13,227 Points

$results->bindParam(1,$members,PDO::PARAM_INT);

I was passing in the wrong value.

Guess, it was close enough.

Thank you again.

Kevin D
Kevin D
8,621 Points

I think it's just that you haven't completed the full code which is causing problems with the previous task when you try to validate your (incomplete) answer.

If you watch the previous video before this code challenge, Alena explains the steps. I think you're missing the bindParam() function which should take in the $members_id variable. Also, the prepare keyword is spelt wrong in your code too!

Robert Stamate
Robert Stamate
13,227 Points

Hey Kevin,

Thanks for the reply, but as I tried to edit I am still stuck. Could you give me another nudge here?

Thank you.

Kevin D
Kevin D
8,621 Points

Hey Robert,

Don't think I can explain it better than Alena but I can show you what I input to pass the code challenge from following her lesson:

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

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

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

Hope that helps!