简体   繁体   中英

Inner join with where clause PHP

I have the following query

$query = "SELECT userRoles.UserRoleType
FROM user
INNER JOIN userRoles
ON user.RoleID = userRoles.RoleID
WHERE( user.UserName = '" . $username . "' AND user.Password = '" . $pass . "')";

Where $username and $pass are variables passed through the form

The query runs fine in phpMyadmin but for some reason it wont run in PHP even though it appears to be returning information.

Tried changing the query multiple times such as moving the WHERE clause above the join, checking table names, googling etc.

Question resolved

When returning the query as an array i had an if statement like this:

if($result[0]>0)
{
  //do something with returned data
}

To resolve the problem i simply had to check if the size of the array was greater than zero indicating that a record had been found.

Here is the solution

if($result>0)
{
  //do something with returned data
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM