【发布时间】:2016-04-09 04:38:28
【问题描述】:
我的项目有员工表,并且它有(姓名、地址...、NIC) 这里 NIC 有模式 9 数字和 V(例如:917200424V),我为此添加了 varchar(100) 类型,
而且这个 NIC 值将进入登录表并且它有 (passowrd, tbl_employee_NIC) 员工表 NIC 值正在传递给此 tbl_employee_NIC。
下面是登录代码:
<?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();
}
?>
但是当我要进入时它给出了一个错误,这里是:
SQLSTATE[42S22]:找不到列:1054 'where 子句'中的未知列'917200500V'
首先我认为错误来自代码,然后我只更新员工表的 NIC 和登录表的 tbl_employee_NIC 中没有“V”的一行。但是它已经成功登录了。那么任何人都可以为此提供解决方案吗?
【问题讨论】: