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

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,646 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,646 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!