简体   繁体   English

SQLSTATE [42S22]:找不到列:1054未知列

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

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, 我的项目有employee表,并且有(名称,地址...,NIC),这里NIC具有模式9的数字和V(例如:917200424V),为此我添加了varchar(100)类型,

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 . 并且此NIC值将要登录表,并且它具有(passowrd,tbl_employee_NIC)员工表NIC值正在传递给此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' SQLSTATE [42S22]:找不到列:1054“ where子句”中的未知列“ 917200500V”

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. 首先,我认为错误是由于代码造成的,然后我只更新了员工表的NIC和登录tavle的tbl_employee_NIC中没有“ V”的一行。 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. 由于tbl_employee_NIC是字符串列,因此数据必须用引号引起来。 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']."'");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQLSTATE[42S22]:未找到列:1054 未知列 - SQLSTATE[42S22]: Column not found: 1054 Unknown column Laravel SQLSTATE [42S22]:找不到列:1054 - Laravel SQLSTATE[42S22]: Column not found: 1054 错误:SQLSTATE[42S22]:未找到列:1054 CakePHP - Error: SQLSTATE[42S22]: Column not found: 1054 CakePHP SQLSTATE [42S22]:找不到列:1054 Laravel - SQLSTATE[42S22]: Column not found: 1054 Laravel 错误:SQLSTATE[42S22]:未找到列:1054 &#39;where 子句&#39;中的未知列 &#39;0&#39; - ERROR: SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' OcotberCMS - “SQLSTATE [42S22]:未找到列:1054未知列&#39;users.application_id&#39; - OcotberCMS - "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.application_id' SQLSTATE [42S22]:找不到列:1054未知列,因为该列存在于我的数据库中 - SQLSTATE[42S22]: Column not found: 1054 Unknown column where as the columns exists in my db SQLSTATE [42S22]:找不到列:1054“ order子句”中的未知列“ B.uid” - SQLSTATE[42S22]: Column not found: 1054 Unknown column 'B.uid' in 'order clause' SQLSTATE[42S22]:未找到列:1054 &#39;field list&#39; 中的未知列 &#39;_token&#39;(SQL:插入到“产品”中 - SQLSTATE[42S22]: Column not found: 1054 Unknown column '_token' in 'field list' (SQL: insert into `products` 如何修复“Illuminate / Database / QueryException with message&#39;SQLSTATE [42S22]:找不到列:1054未知列”? - How to fix “Illuminate/Database/QueryException with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column”?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM