我有一个带有复选框的表格和一个允许用户被“批准”的按钮,数据库中的一个简单的 1 表示他们已被批准。我想先检查一下用户是否已经被批准,这样我就可以显示一条错误消息。然而,在这段代码中最终发生的是,由于某种原因,代码执行底层 sql,但按原样显示错误消息,或者!$check
总是显示成功消息。我尝试了不同的变体,但我感觉问题出在我的 $check sql 逻辑上。我只是似乎看不到它。
if ($_POST['doApprove'] == 'Approve') {
if (!empty($_POST['u'])) {
foreach ($_POST['u'] as $uid) {
$id = filter($uid);
$username[] = get_user_name_from_id($id);
$check = Nemesis::select("approved", "users", "id = '{$id}' AND approved <> '1'"); // issue?
$set_approve = Nemesis::update("users", "approved = '1'", "id = '{$id}'");
if ($check) { // issue?
$fail[] = $username;
} elseif (!$set_approve) {
$fail[] = $username;
} else {
$pass[] = $username;
$user_details = Nemesis::select("*", "users", "id = '{$id}'");
$ud_row = $user_details->fetch_assoc();
authMail('register', $ud_row['user_email'], $ud_row['pwd'], $ud_row['user_name'], NULL, 'admin');
}
}
}
$msg = new Messages();
if (!empty($pass)) {
$passed = implode(', ', $pass);
$message = "Approved: {$passed}";
$msg->add('s', $message);
}
if(!empty($fail)){
$failure = implode(', ', $fail);
$message = "Could not approve {$failure}";
$msg->add('e', $message);
}
redirect('users.php');
}