tags:

views:

58

answers:

1

I want to be able to check my email if it equals $e but my email is in another table called info how can I can I fix this problem?

Here is my MySQL query so far.

"SELECT password, salt FROM users WHERE (email = '" . $e . "' OR username = '" . $e . "') AND active IS NULL"
A: 

Use a JOIN:

SELECT users.password, users.salt
FROM users
JOIN info
ON info.id = users.info_id
WHERE (users.email = $e OR info.username = $e)
AND users.active IS NULL

Note: you may need to modify the line starting ON depending on how you have structured your schema. If you are unsure of what modification to make, update your question to include the output of SHOW CREATE TABLE users and SHOW CREATE TABLE info.

Also you might want to double-check that there isn't an SQL injection vulnerability in your code. It is good practice to use parameters, or at least make sure that the strings are properly escaped. It is not clear from your code extract if you are escaping correctly or not.

Mark Byers
What's the SQL injection comment about?
needHELP
@needHelp, it's about [SQL Injection](http://en.wikipedia.org/wiki/SQL_injection) and if you are asking what it is then your site might be facing a great risk.
Darin Dimitrov
@Darin Dimitrov quick to jump to conclusions believe my I'm using a purifier and escaping my user inputted data.
needHELP
You shouldn't escape your user inputted data. You should use parametrized queries.
Darin Dimitrov
@Mark Byers what is exactly supposed to happen before i go messing around with my database?
needHELP
@needHELP: If you are not escaping correctly it should fetch passwords for all users. You can see how it works if you want, just substitute $e for the above string.
Mark Byers
Try: `')OR(''='`
Mark Byers
@Mark Byers my error message of please try again comes up:)
needHELP
@needHELP: Great, that means either your system is safe from certain types of attack, you copied and pasted incorrectly, or I messed up the query. Hopefully the first of those options.
Mark Byers
@Mark Byers I guess I could not win with you even if I did it correctly :(
needHELP
@needHELP: I think it's unrealistic to *"do it correctly"* - that is make a completely 100% secure site. Even a company like Google or Microsoft makes an error sometimes and leaves a vulnerability in one of their services. But by following best practices you can reduce the number of ways that you can mess up. It seems you are already aware of the issues so that's a good start.
Mark Byers
@needHELp: PS: Did my suggestion of using a JOIN work for you?
Mark Byers
yes it did but I have another problem now.
needHELP