user3649576
user3649576

Reputation: 13

php build query username and password and check result

i would like to ask you about my database query i have this table admin_table in my data base

tag id       name           password       profession 
xxxxxx     Jhon Begly         123            admin

i build a php page to insert a user name and password i need to check the user name and password that i entered with its profession if its valid then proceed with a new page as bellow

$sql = "SELECT * FROM admin_table WHERE name='".$username."' AND password='".$password."'";

so how can i check profession in the same query above any update will be highly appreciated

Upvotes: 0

Views: 77

Answers (2)

islanddave
islanddave

Reputation: 356

You mean this?

$sql = "SELECT * FROM admin_table WHERE name='".$username."' 
        AND password='".$password."' AND profession = 'admin'";

If you get a result row back, you matched all three columns. If zero rows, it failed to match at least one. Not really sure your use case.

I also agree with other commenters that this is far from best practices in several ways.

Upvotes: 0

Tyler
Tyler

Reputation: 183

Where are you validating the profession? If it is in another table... use

INNER JOIN profession_table as pt 
ON pt.some_column

right after the from part of your query

Upvotes: 0

Related Questions