gpt4 book ai didi

php - SQLSTATE[42S22] : Column not found: 1054 Unknown column

转载 作者:行者123 更新时间:2023-11-29 11:47:49 25 4
gpt4 key购买 nike

我的项目有员工表,它有(姓名、地址...、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”的一行。但是已经成功登录了。所以有人能给出解决方案吗?

最佳答案

我认为你的问题可能出在这个声明中。

由于 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']."'");

关于php - SQLSTATE[42S22] : Column not found: 1054 Unknown column,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34610255/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com