doudiaozhi6658 2013-07-02 21:14
浏览 74

foreach循环,检查批准,显示错误数组

I have a table with checkboxes and a button that allows users to be "approved", a simple 1 in the database marks they have been approved. I want to first check to see if the user is ALREADY approved, just so that I can display an error message. However what ends up happening in this code is that for some reason the code executes the underlying sql, but displays the error message as is, or when !$check always display a success message. I have tried different variations but I have a feeling the problem is with my $check sql logic. I just can't seem to see it.

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');
}
  • 写回答

1条回答 默认 最新

  • doutun9179 2013-07-02 21:29
    关注
       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("*", "users", "id = '{$id}'");
                $ud_row = $user_details->fetch_assoc();
                $set_approve = Nemesis::update("users", "approved = '1'", "id = '{$id}'");
                if ($ud_row['approved'] || !$set_approve) {
                    $fail[] = $username;
                } else {
                    $pass[] = $username;
                    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');
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能