skip to Main Content

I am trying to query a simple table to get a users id based on their username. For some reason I am getting a null result for all of my queries.

Table creation:

CREATE TABLE users(
user_id int not null auto_increment primary key,
username text not null,
password text not null
) ENGINE=InnoDB;

Inserting a tuple:

INSERT INTO `users` (`user_id`, `username`, `password`) VALUES (NULL, 'joe', '1234');

Selecting user id based on username:

SELECT 'user_id' FROM `users` WHERE 'username' = 'joe'

Returns 0 rows… yet when I click on the table users I can see the row with username joe.

I am executing the queries in PHPMyAdmin with the users table selected so I am pretty sure it is not a schema issue.

2

Answers


  1. The reason you are getting an empty result is because you’re using the wrong column delimiter in your select query. Try swapping the apostrophe for a backtick character.

    SELECT `user_id` FROM `users` WHERE `username` = 'joe';
    
    Login or Signup to reply.
  2. Try this

    SELECT `user_id` FROM `users` WHERE `username` = 'joe'
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search