MYSQL client

Post here if you need help with SQL.
Post Reply
jonathon
Posts: 50
Joined: Fri May 06, 2011 5:09 pm

MYSQL client

Post by jonathon »

Hi,

I'm driving myself mad here, I've written a login script which isn't working so I thought I'll go into my PHPmyAdmin and use the client. My email and username return no results using this query:

[syntax=sql]
SELECT id, firstName
FROM users
WHERE (`email` = 'myemail@example.com' AND `password`= '544sd4a5d4as5d4fsd4f') // This a long hash
[/syntax]

The query doesn't fail it just returns no records and i'm using the values already stored in the DB. If i just search for a column that isn't the password column it returns the information. But as soon as I involve the password column in a combination WHERE or on its own it fails. And I'm copying and pasting the value from the database.

What am I dong wrong? :-(
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: MYSQL client

Post by jacek »

Hmm, it looks okay overall. The only thing I can think of is that id is a mysql keywords, so try wrapping all of the column and table names in backticks. I tend to do this any way just to avoid there being any problems.
Image
jonathon
Posts: 50
Joined: Fri May 06, 2011 5:09 pm

Re: MYSQL client

Post by jonathon »

Yeah I did try that, same result. I don't know whether to be pleased that i'm not going mad or disappointed that it isn't just an oversight. I don't see what's wrong with the pword column :S
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: MYSQL client

Post by jacek »

Maybe try it without the brackets then, since they usually indicate a sub-query

[syntax=sql]SELECT
`id`,
`firstName`
FROM `users`
WHERE `email` = 'myemail@example.com'
AND `password`= '544sd4a5d4as5d4fsd4f'[/syntax]

??
Image
jonathon
Posts: 50
Joined: Fri May 06, 2011 5:09 pm

Re: MYSQL client

Post by jonathon »

Hmm, still the same, I'm at a loss.
This is as simple I can make the query and it still fails
[syntax=sql]
SELECT `firstName` FROM `users` WHERE `password` = '544sd4a5d4as5d4fsd4f'
[/syntax]
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: MYSQL client

Post by jacek »

Right, :?

Are you sure the password in the table is the same ? Check to make sure it does not have a space or somethign after it.
Image
jonathon
Posts: 50
Joined: Fri May 06, 2011 5:09 pm

Re: MYSQL client

Post by jonathon »

I think it might have been because i'm storing the password in binary so that's why the client didn't return the row when using the password value. Not sure though, thanks for the help.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: MYSQL client

Post by jacek »

Oh, not an unsolved topic ! As long as you got it working :D
Image
jonathon
Posts: 50
Joined: Fri May 06, 2011 5:09 pm

Re: MYSQL client

Post by jonathon »

Yeah - thanks Jacek :D
Post Reply