If you try this:
SELECT 8='8k'
you can see that it returns true! That's because 8 is a int, and 8k
is a string, and 8k
converted to int becomes 8.
This returns false instead:
SELECT CAST(8 as char)='8k'
So you have to write your query like this:
SELECT name FROM users WHERE CAST(user_id as char)='$user_id'
Or you have to make sure that $user_id is numeric, and remove '
:
SELECT name FROM users WHERE user_id=$user_id