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

how can I change the function to select a single member from member_id

To set up an account page, you need to select a single member. Change the function to accept the single argument for a member_id.

I don't understand what function I need to change I tried modifying fetchALL to just fetch and also tried calling it in member_id in fetch

fetch(member_id);

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

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

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

5 Answers

Robert Stamate
Robert Stamate
13,227 Points

(<?php function get_member($member_id))

This should fix it out for you. And I guess you figure it where it was the function argument.

it returned error maybe we need to change something else i Have tried a lot of things to solve this

To set up an account page, you need to select a single member. Change the function to accept the single argument for a member_id.

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

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

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

}

I got it now I forgot the $ sign in my function

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

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

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

}

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

try {
  $results = $db->query(
      "SELECT member_id
      FROM members WHERE member_id= '$member_id' "
  );
} catch (Exception $e) {
  echo "bad query";
}

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

}

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

try {
  $results = $db->query(
      "SELECT member_id
      FROM members WHERE member_id= '$member_id' "
  );
} catch (Exception $e) {
  echo "bad query";
}

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

}

Robert Stamate
Robert Stamate
13,227 Points

My bad, I forgot to add it in the first place as well.

I'm clumsy. Sorry.

no worries you pointed me to the right direction thanks for your help.