Взгляните на это и, пожалуйста, еще раз продумайте свой код, особенно в отношении уязвимости XSS!Кроме того, ради хорошего разработчика, реорганизуйте / перепишите свою базу данных.Это ВСЕ, кроме пути.
Кроме того, код не проверен.
<?php
$db = getConnection(); //assuming you are returning a PDO object here!
$username = getUsername(); //assuming you are NOT escaping the username!
$password = getPassword(); //assuming your hashed password here!
$query = "SELECT password, salt, 'emplyer' as user_type
FROM JB_Employer
WHERE Username = :username
UNION
SELECT password, salt, 'jobseeker' as user_type
FROM JB_Jobseeker
WHERE User_Name = :username";
//$statement == PDOStatement
$statement = $db->prepare($query);
//bind the $username param to :username, this is the real power of PDO,
//no more SQL Injections. Don't use mysql_real_escape-esque things!
//they are not nececary with PDO
$statement->bindParam(":username", $username);
//execute the statement
if($statement->execute()){
$result = $statement->fetchAll();
$rowCount = count($result);
if($rowCount < 1){
// redirect?
die("No Such user");
}else{
// more than one user can be possible, this is not the correct way, but it appears to be your way so let's continue
$firstRow = $result[0];
if( isPasswordEqual($firstRow['salt'], $password) ){
$_SESSION['user'] = $username; //security risk here. Vulnerable for XXS
$_SESSION['permission'] = $firstRow['user_type'];
}else{
//Don't tell them this! It will give them knowledge of which accounts do exist.
//Just say some general message like "login failed"
die("wrong information");
}
}
}