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

Jacob Wick
Jacob Wick
8,912 Points

What's wrong with my WHERE clause here?

I'm passing $member_id through the function and checking that members.member_id matches $member_id, aren't I? Or maybe not...

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

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

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

1 Answer

Niki Molnar
Niki Molnar
25,698 Points

Hi Jacob

If you’re not joining two tables, you don’t need to include the members table name before the field name, so:

members.member_id = $member_id

can become:

member_id = $member_id

It should work in a production environment but sometimes the Treehouse algorithm doesn’t always take that into account!

Good luck and I hope that helps.

Niki