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 Valencia
PLUS
Robert Valencia
Courses Plus Student 3,735 Points

I am getting the message: “Your function should accept 1 argument for member_id.” Could someone provide sample code?

I tried adding the code as it was shown in the video, but I’m not sure what I’m missing.

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


    try {
      $results = $db->perpare(
          "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";
      echo $e;
    }

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

1 Answer

Joel Bardsley
Joel Bardsley
31,244 Points

try { $results = $db->perpare(

Typo above needs fixing.

Robert Valencia
Robert Valencia
Courses Plus Student 3,735 Points

Thank you Joel, I corrected that typo, crossed my fingers, but I’m still getting the same error message: “Your function should accept 1 argument for member_id”. Any other suggestions?

Joel Bardsley
Joel Bardsley
31,244 Points

I was on my phone yesterday so wasn't able to run through the challenge. I assume you previously had an $id argument in the get_member function, ie get_member($id) - for some reason you seem to have removed it, so there's no longer a reference to $id that can be used in the $results->bindParam() method.

Also, there was no need to change the returned $members value. Reset this back to $members = $results->fetchAll(); as well as make the corrections above and the challenge should pass.

Robert Valencia
Robert Valencia
Courses Plus Student 3,735 Points

Thank you so much Joel! Your answers really walked me through it and helped me see the glaring adjustments that were not obvious to me.

Cheers!