My Project has employee table and it has (name, address ... , NIC) Here NIC has pattern 9 numbers and V (Ex: 917200424V) and i have add varchar(100) type for that,
And this NIC value is going to login table and it has (passowrd, tbl_employee_NIC) Employee table NIC value is passing to this tbl_employee_NIC .
Bellow is the code for login :
<?php
require_once '../../config/config.php';
$tbl_employee_NIC = $_POST['tbl_employee_NIC'];
$passwordI = $_POST['password'];
$passwordI = md5($passwordI);
try {
$sql = "SELECT e.NIC, e.status, e.employeeBranch, e.employeeRole,
l.status,l.tbl_employee_NIC, l.password
FROM tbl_employee e, tbl_login l
WHERE l.tbl_employee_NIC=:tbl_employee_NIC
AND l.tbl_employee_NIC=e.NIC
AND e.status='Active'";
$stmt = $conn->prepare($sql);
$stmt->execute(array(':tbl_employee_NIC' => $tbl_employee_NIC));
$result = $stmt->fetchAll();
if (count($result)) {
$row = $result[0];
$dbPassword = $row[6];
if ($passwordI == $dbPassword) {
$_SESSION['username'] = $row[0];
$_SESSION['Branch'] = $row[2];
$_SESSION['Role'] = $row[3];
//update active in login
$stmt = $conn->prepare("UPDATE `tbl_login`
SET `status`='Active'
WHERE tbl_employee_NIC=".$_SESSION['username']);
$stmt->execute();
// ./update active in login
$_SESSION['SUCCESS'][] = "Welcome! ".$_SESSION['username'];
header("Location: " . '../login/home.php');
} else {
header("Location: " . $_SERVER['HTTP_REFERER']);
$_SESSION['ERROR'][] = "User Name or Password is wrong..!";
}
} else {
header("Location: " . $_SERVER['HTTP_REFERER']);
$_SESSION['ERROR'][] = "You have trun over the company .. SORRY!";
}
} catch (Exception $ex) {
header("Location: " . $_SERVER['HTTP_REFERER']);
$_SESSION['ERROR'][] = $ex->getMessage();
}
?>
But it gives an error when i am going to enter , Here it is :
SQLSTATE[42S22]: Column not found: 1054 Unknown column '917200500V' in 'where clause'
Firstly i thought the error is from code then i just update one row without "V" in NIC of employee table and tbl_employee_NIC of login tavle. But it has successfully logged in. so could anyone give the solution for this?
I think your problem is probably in this statement.
As tbl_employee_NIC
is a string column the data must be wrapped in quotes. So amend the query like this
//update active in login
$stmt = $conn->prepare("UPDATE `tbl_login`
SET `status`='Active'
WHERE tbl_employee_NIC='{$_SESSION['username']}'");
Or if you prefer
//update active in login
$stmt = $conn->prepare("UPDATE `tbl_login`
SET `status`='Active'
WHERE tbl_employee_NIC='".$_SESSION['username']."'");
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.