Good evening, I am just trying out something new (to me atleast) on how to login from different tables. Table1 has the cand_id (username) while Table2 has the pincode (password). The server doesn't display any error when I try to login but its not working. My code below:
if (isset($_POST['cand_id'])) {
//escapes special characters in a string
$cand_id = mysqli_real_escape_string($con,$cand_id);
$pincode = mysqli_real_escape_string($con,$pincode);
//Checking is user existing in the database or not
$query = "SELECT cand_id
FROM candidates
WHERE cand_id='$cand_id'
UNION
SELECT pincode
FROM cand_login
WHERE pincode='$pincode'";
$result = mysqli_query($con,$query) or die(mysql_error());
$rows = mysqli_num_rows($result);
if($rows==1) {
$_SESSION['cand_id'] = $cand_id;
// Redirect user to index.php
header("Location: home.php");
} else {
echo "<div class='form'>
<h3>cand_id/pincode is incorrect.</h3>
<br/>Click here to <a href='log.php'>Login</a></div>";
}
} else {
}
What do I need to make this work?