开发者

MySQL multiple tables problem?

开发者 https://www.devze.com 2023-01-18 06:21 出处:网络
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?

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"


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消