I am trying to check login credentials against 2 different tables and the query keeps coming back saying that the user doesn’t exist. I will try to explain what I am doing…
I have a table called customers that stores customer data only. I have another table called admins that stores credentials for admins only.
I would like to have the admins be able to log in to the site using the same log in screen as the customers. Once they are logged in, the system will know that they are an admin and display the proper widgets for administrating the product data on the site.
I inserted a dummy user in the admins table and ran this query:
$sql = mysql_query("SELECT EXISTS(
SELECT 1 FROM `customers` WHERE `email` = 'johndeere@whatever.com' AND `password` = 'password'
UNION
SELECT 1 FROM `admins` WHERE `Email` = 'johndeere@whatever.com' AND `Password` = 'password'
)");
$result = @mysql_query($sql);
if(!$result) {
echo "User doesn't exist!";
} else {
echo "User exists!";
}
This query is coming back saying “User doesn’t exist” when I know for a fact they are in the admins table. I’m sure that I am missing something very simple and was hoping someone could help me out with what it is.
I am still pretty new to mySQL and PHP but I am learning fast. This is, so far, the only problem that I could not fix or find an answer for. Your help is greatly appreciated. Thanks in advance.
why don’t you use,
your query will return 0(false), 1(true), you need to check these values, if you use original query
You can’t use
!$resultas it only tells weather query was legal or not., you need to retrieve the data.Refer this: http://www.php.net/manual/en/function.mysql-query.php