如何检查多个isset($_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');
答案 0 :(得分:2)
isset
接受多个变量
在您的情况下,您可以
if (!isset($_POST['username'], $_POST['email'], $_POST['password'], $_POST['confirm_pass'], $_POST['gender'], $_POST['country']) ) {
}
我还应该提到isset
只有在设置了所有变量
http://php.net/manual/en/function.isset.php
来自Doc:
如果提供了多个参数,则isset()将仅返回TRUE 如果设置了所有参数。评估从左到右 并在遇到未设置的变量时立即停止。
答案 1 :(得分:0)
检查空/未设置字段的更好方法可能是这样的。玩这个以达到预期的效果:
<?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');
}
}
?>
答案 2 :(得分:0)
empty
将返回错误或通知。
我个人使用!isset
功能。