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

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.