当前位置: 首页 > 知识库问答 >
问题:

未捕获的异常“PDOException”(带有消息“SQLSTATE[42S22]):未找到列:1054”Field List“中的未知列”UserType“)

严斌
2023-03-14

我试图将以下代码实现到我的网站上,但出现了这个错误:

致命错误:未捕获异常“PDOException”,消息为“SQLSTATE[42S22]:找不到列:1054在/home/multive2/public_html/superdonate/ajax/login.php中的”field list“中存在未知列”usertype“:63堆栈跟踪:#0/home/multive2/public_html/superdonate/ajax/login.php(63):pdostatement->execute(数组)#1{main}在

为什么会这样?对不起,我的英语/代码。

        if(curl_errno($curl)){
            array_push($pageError, getLangString("process-request-error"));
            array_push($pageError, curl_errno($curl));
        } else {
            $returnedDecoded = json_decode($returned, true);
            if(isset($returnedDecoded['success'])){
                if($returnedDecoded['success'] === true){
                    $moveOn = true;
                } else {
                    array_push($pageError, getLangString("retry-captcha"));
                }
            } else {
                array_push($pageError, getLangString("process-request-error"));
            }
        }

    } else {
        $moveOn = true;
    }

    if($moveOn === true) {
        if($_POST['login-type'] == "login"){
            $username = $_POST['username'];
            $password = $_POST['password'];
            $sql = $dbcon->prepare("SELECT password, usertype FROM users WHERE username=:username");
            $value = array(':username' => $username);
            $sql->execute($value);  -----------------------------> Line 63, Error.
            $result = $sql->fetchAll(PDO::FETCH_NUM);
            $count = 0;
            foreach ($result as $key => $value) {
                $count = $count + 1;
            }
            if($count < 1){
                array_push($pageError, getLangString("incorrect-login"));
            } else {
                if(password_verify($password, $result[0][0]) == true){
                    $_SESSION['username'] = $username;
                    if($result[0][1] === 'admin'){
                        $_SESSION['admin'] = TRUE;
                    }
                } else {
                    array_push($pageError, getLangString("incorrect-login"));
                }
            }
        } elseif ($_POST['login-type'] == "register"){
            $username = $_POST['username'];
            $password = $_POST['password'];
            $confirmpassword = $_POST['confirm-password'];
            $email = $_POST['email'];
            $uservalid = FALSE;
            $passvalid = FALSE;
            $emailvalid = FALSE;
            $sql = $dbcon->prepare("SELECT password FROM users WHERE username=:username");
            $value = array(':username' => $username);
            $sql->execute($value);
            $result = $sql->fetchAll(PDO::FETCH_NUM);
            $count = 0;
            foreach ($result as $key => $value) {
                $count = $count + 1;
            }
            if($count > 0){
                array_push($pageError, getLangString("username-taken"));
            } else {
                if($password === $confirmpassword){
                    if(strlen($username) < 6 OR strlen($username) > 32){
                            array_push($pageError, getLangString("username-length-error"));
                    } else {
                            $uservalid = TRUE;
                    }
                    if(strlen($password) < 8){
                        array_push($pageError, getLangString("password-length-error"));
                    } else {
                        $passvalid = TRUE;
                    }

                    $url = $sdonateapiurl;
                    $data = array('action' => 'validateemail', 'apikey' => $sdonateapi, 'email' => $_POST['email']);
                    $options = array(
                        'http' => array(
                            'header'  => "Content-type: application/x-www-form-urlencoded",
                            'method'  => 'POST',
                            'content' => http_build_query($data),
                        ),
                    );
                    $context  = stream_context_create($options);
                    $result = file_get_contents($url, false, $context);

                    if($result === FALSE){
                        array_push($pageError, getLangString("process-request-error"));
                    } elseif($result === "apiproblem") {
                        array_push($pageError, getLangString("api-key-problem"));
                    } elseif($result === "EMAILINVALID") {
                        array_push($pageError, getLangString("invalid-email-error"));
                    } elseif($result === "EMAILVALID") {
                        $emailvalid = true;
                    }

                    if($uservalid === TRUE AND $passvalid === TRUE AND $emailvalid === true){
                        $hashed = password_hash($password, PASSWORD_DEFAULT);
                        if($hashed === FALSE){
                            array_push($pageError, getLangString("account-registration-error"));
                        } else {
                            $sql = $dbcon->prepare("INSERT INTO users(username, email, password, usertype) VALUES(:username, :email, :password, :usertype)");
                            $values = array(':username' => $username, ':email' => $email, ':password' => $hashed, ':usertype' => 'user');
                            $sql->execute($values);
                            $_SESSION['username'] = $username;
                        }
                    }
                } else {
                    array_push($pageError, getLangString("password-mismatch-error"));
                }
            }
        } elseif($_POST['login-type'] == "resetpassword"){

            $key = $_POST['reset-password-key'];
            $username = $_POST['username'];
            $password = $_POST['password'];
            $confirmpassword = $_POST['confirmpassword'];

            $sql = $dbcon->prepare("SELECT * FROM resetpassword WHERE username=:username AND resetkey=:resetkey");
            $values = array(':username' => $username, ':resetkey' => $key);
            $sql->execute($values);
            $results = $sql->fetchAll(PDO::FETCH_ASSOC);
            $resultscount = $sql->rowCount();

            if($resultscount > 0){
                if(strtotime($results[0]['expires']) > time() - 86400){
                    if($password === $confirmpassword){
                        if(strlen($password) > 7){
                            $hashed = password_hash($password, PASSWORD_DEFAULT);
                            if($hashed === FALSE){
                                array_push($pageError, getLangString("password-change-error"));
                            } else {
                                $sql = $dbcon->prepare("UPDATE users SET password=:password WHERE username=:username");
                                $values = array(':password' => $hashed, ':username' => $username);
                                $sql->execute($values);
                                $sql = $dbcon->prepare("DELETE FROM resetpassword WHERE username=:username AND resetkey=:resetkey");
                                $values = array(':username' => $username, ':resetkey' => $key);
                                $sql->execute($values);
                            }
                        } else {
                            array_push($pageError, getLangString("password-length-error"));
                        }
                    } else {
                        array_push($pageError, getLangString("password-mismatch-error"));
                    }
                } else {
                    array_push($pageError, getLangString("password-link-expired-error"));
                }
            } else {
                array_push($pageError, getLangString("password-link-invalid-error"));
            }
        } else {
            array_push($pageError, getLangString("invalid-request-error"));
        }
    }
} else {
    array_push($pageError, getLangString("retry-captcha"));
}
}

if(count($pageError) > 0){
    foreach ($pageError as $key => $value) {
       print('<span>' . $value . '</span><br>');
    }
}

对此我很抱歉

描述用户

共有1个答案

孙博艺
2023-03-14

作为社区维基发布。(这件事不应该有代表)。

错误很清楚,usertype列不存在。

您可以创建它,也可以从查询中删除它。

 类似资料:
  • 我使用的框架Laravel。 我有两个表(用户和成员)。当我想登录时,我会收到错误消息: SQLSTATE[42S22]:找不到列: 1054未知的列'user_email'in'where子句'(SQL:选择*fromwhere=?限制1)(绑定:数组(0= 表用户 表成员 迁移用户 移民成员 模型用户 模范会员 成员模型使用:使用照明\Auth\UserInterface; 控制器 auth.

  • 我是编程界的新手,我自己在学习laravel,我发现了这个错误:SQLSTATE[42S22]:Column not found:1054未知列'clientes.clientes\u id'在'where子句中(SQL:select*fromwhere=1和不为空)(视图:/shared/httpd/laravel_8_crud/resources/views/pedidos/index.bla

  • 我正在制作一个我想登录和注册的应用程序,并且能够将csv文件导入数据库,注册和登录工作正常,但是当我想导入csv时,我遇到了这个问题: 错误luminate\Database\QueryException SQLSTATE[42S22]:未找到列:1054“where子句”中的未知列“classe”(SQL:select*fromwhere(=7和=7598)限制1)科目表 账户控制员

  • 我正在尝试使用PDO向MySQL插入一条记录,下面的代码中可以看到我的sql语句。 当执行此代码时,我会遇到以下错误消息; SQLState[42S22]:找不到列:1054“Field List”中的未知列“John” 这无疑是解决这个问题的一个简单方法,但我似乎看不出来,有人能给我指明正确的方向吗?

  • 我尝试使用php artisan tinker创建管理员用户。当我尝试保存时,它返回一个错误。请帮我解决这个问题。 这里是错误 Illumb/Database/QueryException,消息为“SQLSTATE[42S22]:未找到列:字段列表中的1054未知列“admin”(SQL:updateset=2018-12-28 05:41:31,=1其中=1)

  • 我的代码:数据库中的值未更新,出现以下错误: (照明\数据库\查询异常(42S22)SQLSTATE[42S22]:找不到列: 1054未知列'用户名'在'where子句'(SQL:选择计数()作为聚合从其中=anikatabassum))和("SQLSTATE[42S22]:找不到列: 1054未知列'用户名'在'where子句'(SQL:选择计数()作为聚合从其中=anikatabassum)