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