我的项目有员工表,它有(姓名,地址......,网卡) 这里 NIC 有模式9号码和V(例如:917200424V),我为此添加了varchar(100)类型,
此NIC值将进入登录表并且具有(passowrd,tbl_employee_NIC) 员工表 NIC 值传递给此 tbl_employee_NIC 。
Bellow是登录的代码:
<?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未知列&#39; 917200500V&#39;在&#39; where子句&#39;
首先我认为错误是来自代码,然后我只更新一行而没有&#34; V&#34;在employee表的 NIC 和login tavle的 tbl_employee_NIC 中。但它已成功登录。所以有人可以为此提供解决方案吗?
答案 0 :(得分:1)
我认为你的问题可能出在这个声明中。
由于tbl_employee_NIC
是一个字符串列,因此数据必须用引号括起来。所以像这样修改查询
//update active in login
$stmt = $conn->prepare("UPDATE `tbl_login`
SET `status`='Active'
WHERE tbl_employee_NIC='{$_SESSION['username']}'");
或者如果您愿意
//update active in login
$stmt = $conn->prepare("UPDATE `tbl_login`
SET `status`='Active'
WHERE tbl_employee_NIC='".$_SESSION['username']."'");