I've two tables (clients, admin) A person logs in by email and password, I have to see if either the e-mail and password is available within the customer or admin table. Your email are unquie so will not have trouble there. To uni work, clearly I'd possess a better database design than this but I must use what's given. I've this:
$email = $_POST['email']; $password = $_POST['password']; $sql = "SELECT * FROM customer, admin WHERE cus_email = '$email' AND cus_password = '$password' OR admin_email = '$email' AND admin_password = '$password'";
Am not so good with Joins and so i havent attempted one about this.
Thank you for any help :)
You actually need a UNION as opposed to a JOIN here:
SELECT username FROM Customer WHERE cus_email = ? AND cus_password = ? UNION SELECT adminname AS username FROM admin WHERE admin_email = ? AND admin_password = ?
You need to either use placeholders - the question marks - or safeguard yourself against SQL Injection attacks. You will find functions that will help you do this in PHP.
SELECT cus_id as id, 'false' as IsAdmin FROM customer WHERE cus_email = '$email' AND cus_password = '$password' UNION ALL SELECT admin_id as id, 'true' as IsAdmin FROM admin WHERE admin_email = '$email' AND admin_password = '$password'";