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