Reputation: 1298
I have a database where I have an email field, among others.
When I do a SELECT statement like :
SELECT * FROM table_name WHERE email = '[email protected]';
...it returns an empty set, even though I can see the entry in the table.
The same statement works when I use:
SELECT * FROM table_name WHERE fname = 'abcd';
What could be going wrong?
Upvotes: 1
Views: 105
Reputation: 1298
I got it to work after a small but unintended change.
My old PHP query goes like this :
$res = mysql_query("SELECT * FROM books WHERE email = '$email'");
My new and changed query goes like this :
$res = mysql_query("SELECT * FROM books WHERE email = ' $email'");
For some reason, mysql_real_escape_string() was adding one extra space at the beginning, I think, which wasn't visible in PHPMyAdmin.
Upvotes: 0
Reputation: 3548
Try this and check whether you are getting results for [email protected] or not.
SELECT *
FROM table_name
WHERE email LIKE '%abcd@%'
Upvotes: 0
Reputation: 30488
use trim
in your query
SELECT * FROM table_name WHERE TRIM(`email`) = '[email protected]';
http://sqlfiddle.com/#!2/90a95/3
Upvotes: 2
Reputation: 2540
try below code. thinks it will help you.
SELECT * FROM table_name WHERE `email' = '[email protected]';
Upvotes: -1
Reputation: 450
Does the entry contain extra spaces (tabs etc.) maybe? You can try to:
SELECT * FROM table_name WHERE email LIKE '[email protected]%'
and
SELECT * FROM table_name WHERE email LIKE '%[email protected]'
to see if that's the case
Upvotes: 0
Reputation: 9158
Are you sure you do not have additional spaces? try with LIKE
clause
SELECT * FROM table_name WHERE email LIKE '%[email protected]%'
Upvotes: 0
Reputation: 46900
Maybe there are some spaces in the entry that is stored in MySQL, Check if the stored email is exactly that without any blank space or unexpected character. You can also try the following to confirm this
SELECT * FROM table_name WHERE email LIKE '%[email protected]%'
Upvotes: 0