gpt4 book ai didi

php - 未捕获的异常 'PDOException',消息为 'SQLSTATE[42S22]: Column not found: 1054 Unknown column ' usertype' in 'field list' '

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

我尝试在我的网站上实现以下代码,但出现此错误:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'usertype' in 'field list'' in /home/multive2/public_html/superdonate/ajax/login.php:63 Stack trace: #0 /home/multive2/public_html/superdonate/ajax/login.php(63): PDOStatement->execute(Array) #1 {main} thrown in /home/multive2/public_html/superdonate/ajax/login.php on line 63"

为什么会发生这种情况? 对我的英语/代码感到抱歉。

        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>');
}
}

对此感到抱歉

DESCRIBE users

最佳答案

作为社区 wiki 发布。 (不应有代表出现)。

错误已明确,usertype 列不存在。

要么创建它,要么从查询中删除它。

关于php - 未捕获的异常 'PDOException',消息为 'SQLSTATE[42S22]: Column not found: 1054 Unknown column ' usertype' in 'field list' ',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40430936/

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