我的项目有员工表,并且有(名称,地址...,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和登录tavle的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']."'");

09-25 18:36
查看更多