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

Development Tools Using PHP with MySQL Querying the Database with PHP Querying the Database

Neeta Ghosh
Neeta Ghosh
839 Points

I am getting "Error:Table database.tablename does not exist". I'm connected to the db and 'show tables' works.

I am using mysqli extensions. I am able to connect to the database and also seeing the table name using "show tables". However when I try to select on the table, I am getting this error.

Here's my code that is generating the error

if ($result = mysqli_query ($connection, "select * from mytable  where LNAME = '$user_lname'")) {
            if ( ($row_count = mysqli_num_rows($result)) > 0) {
                printf("Oops! Looks like we already have someone else using your username $user_lname. Please choose a differnt username and try again. \n  ");
                exit();
            }
            mysqli_free_result($result);            
        }

Try specifying the table name in the database.table format. You may not be connected to the correct database. I have been going round and round with mysqli errors for several days. Each time, the query that worked is the exact same query I entered in the first place. another thing I noticed is that you are establishing your connection and running the query ion the same line. Try establishing the connection separately. While it should not matter, you do have 2 spaces in between your table name and the WHERE keyword. sometimes this could introduce a stray character that would make the table name invalid,. I hope this helps!!!