Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am building a VPS node that is running Ubuntu 10.10LTS, Apache2, Mysql 5.1 and php5.

I could not log in to my website admin through the browser, even though I am using the correct login details. So I logged in from the command line to check the results.

When I run this query I get expected results:

mysql> select * from users;
+----+----------+-----------------------+----------+
| id | username | email                 | password |
+----+----------+-----------------------+----------+
|  1 | myUserName    | myUserName@mysite.com | myPassword |
+----+----------+-----------------------+----------+

And the same goes for this query:

mysql> select * from users where id = 1;
+----+----------+-----------------------+----------+
| id | username | email                 | password |
+----+----------+-----------------------+----------+
|  1 | myUserName    | myUserName@mysite.com | myPassword |
+----+----------+-----------------------+----------+
1 row in set (0.00 sec)

But when I run this query I get this 'unexpected response':

mysql> select * from users where username = 'myUserName' and password = 'myPassword';
Empty set (0.00 sec)

I am not sure why this is happening. Any help would be greatly appreciated. BTW.. I will be encrypting the user details but for now I just want to get it set up.

Please help,

Thanks

share|improve this question
1  
Don't you have whitespaces after 'myUserName' ? –  CloudWeavers Apr 13 '12 at 16:33
    
@CloudWeavers might be onto something; try using username LIKE '%myUserName%' to verify? –  Andrew M. Apr 13 '12 at 16:36
    
@Andrew -- yh that query worked –  user866190 Apr 13 '12 at 16:44
    
@Andrew --still not sure how to get the original query to work though –  user866190 Apr 13 '12 at 16:44
1  
Just a minor nitpick. Ubuntu 10.10 is not an LTS release. –  Zoredache Apr 13 '12 at 16:58
show 1 more comment

2 Answers

up vote 3 down vote accepted

Just to turn it into an answer, based on the formatting of your SQL queries, it looks like you have spaces in the field for your username. That is:

mysql> select * from users where id = 1;
+----+----------+-----------------------+----------+
| id | username | email                 | password |
+----+----------+-----------------------+----------+
|  1 | myUserName    | myUserName@mysite.com | myPassword |
+----+----------+-----------------------+----------+
1 row in set (0.00 sec)

In other words, the username field for id=1 is myUserName___, where the _ are used to illustrate spaces. That's why, when you use username LIKE 'myUserName%' (which says include everything that begins with myUserName) works correctly.

share|improve this answer
    
Arrgh, thanks. I spot the error now, a space after my username on my db_setup script. Thanks again –  user866190 Apr 13 '12 at 16:58
    
Glad to help; these kind of things can be extremely frustrating to spot at times! –  Andrew M. Apr 13 '12 at 16:59
1  
Arrrggg. I should have pushed that as an answer. –  CloudWeavers Apr 13 '12 at 17:31
add comment

Password is also the name of a mysql function that hashes passwords; I wonder if this could be the problem? Try quoting the table names.

Additionally, there appears to be some whitespace after the string myUserName. I suspect this indicates an application error. If you were to update users set username='myUserName' where id=1; you would likely find it works.

share|improve this answer
    
Thx, tried double and single quotes, plus these style quotes(not sure what there called): ``, also tried renaming the tables. The same query works fine on the dev box. Not sure what to do..;. –  user866190 Apr 13 '12 at 16:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.