Php 如何检查多个isset($#u POST[';something';])?

Php 如何检查多个isset($#u POST[';something';])?,php,codeigniter-2,Php,Codeigniter 2,如何检查多个isset($\u POST['something'])?使用下面提到的代码函数调用时是否不设置任何内容?我犯了什么错误 我的密码在这里 if(!isset($_POST['username']) || $_POST['email'] || $_POST['password'] || $_POST['confirm_pass'] || $_POST['gender'] || $_POST['country']== "") { $username = $this->inp

如何检查多个
isset($\u POST['something'])
?使用下面提到的代码函数调用时是否不设置任何内容?我犯了什么错误

我的密码在这里

if(!isset($_POST['username']) || $_POST['email'] || $_POST['password'] || $_POST['confirm_pass'] || $_POST['gender'] || $_POST['country']== "") 

{   $username = $this->input->post('username');
    $email = $this->input->post('email');    
    $password = $this->input->post('password');
    $confirm_password = $this->input->post('confirm_pass');
    $gender = $this->input->post('gender');
    $country = $this->input->post('country');
    $this->signupdata->submit_data($username,$email,$password,$confirm_password,$gender,$country);     
 exit(); }
 $this->load->view('signup_view'); 

isset
接受多变量

在你的情况下,你可以这样做

if (!isset($_POST['username'], $_POST['email'], $_POST['password'], $_POST['confirm_pass'], $_POST['gender'], $_POST['country']) ) {

}
我还应该提到,
isset
只有在设置了所有变量后才会返回true

从文件:

如果提供了多个参数,则isset()将仅返回TRUE 如果所有参数都已设置。计算从左到右 并在遇到未设置的变量时立即停止


检查空/未设置字段的更好方法可能如下所示。围绕这一点进行操作,以达到预期的效果:

<?php   
    $req = array("username", "email", "password", "confirm_pass", "gender", "country");
    foreach($req AS $r) {
        if(empty($_POST[$r])) {
            $error = $r . " is a required field";
        } else {
            $username = $this->input->post('username');
            $email = $this->input->post('email');    
            $password = $this->input->post('password');
            $confirm_password = $this->input->post('confirm_pass');
            $gender = $this->input->post('gender');
            $country = $this->input->post('country');
            $this->signupdata->submit_data($username,$email,$password,$confirm_password,$gender,$country);     
            exit();
            $this->load->view('signup_view');
        }    
    }
?>

empty
如果未设置字符串,则返回错误或通知


我个人使用
!isset
功能。

!ISSET($POST POST[用户名]),$POST([电子邮件] ]…< /代码>或继续添加相同的条件。因此,OP得到他们的答案并跑掉了FYI和“堆栈滚动”:考虑接受答案。下面是如何返回此处并对勾号/复选标记执行相同操作,直到其变为绿色。这会通知社区,找到了解决方案。否则,其他人可能会认为问题仍然悬而未决,并希望发布(更多)答案。如果使用空,则不需要
!isset