Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果未选中“全部”复选框,则显示错误消息的Php(多个复选框)_Php - Fatal编程技术网

如果未选中“全部”复选框,则显示错误消息的Php(多个复选框)

如果未选中“全部”复选框,则显示错误消息的Php(多个复选框),php,Php,在我的Html表单中,用户可以选择或不选择的复选框字段很少。现在,如果用户选中所有复选框,则表单显示成功消息,但如果未选中所有复选框,则显示多条错误消息。所以它没有显示成功的信息。错误消息如下所示: Notice: Undefined variable: mon_morning in D:\software installed\xampp installed\htdocs\tutor \tutor_request.php on line 142 Notice: Undefined variab

在我的Html表单中,用户可以选择或不选择的复选框字段很少。现在,如果用户选中所有复选框,则表单显示成功消息,但如果未选中所有复选框,则显示多条错误消息。所以它没有显示成功的信息。错误消息如下所示:

Notice: Undefined variable: mon_morning in D:\software installed\xampp installed\htdocs\tutor
\tutor_request.php on line 142

Notice: Undefined variable: mon_afternoon in D:\software installed\xampp installed\htdocs\tutor
\tutor_request.php on line 142

more.....
我的html复选框表单:

<table width="500" border="0" cellspacing="0" cellpadding="0">  
  <tr>
    <td><input type="checkbox" name="mon_morning" value="mon_morning" id="checkAll"/>&nbsp;<strong>MON</strong></td>
    <td><input type="checkbox" name="mon_morning" value="mon_morning" class="checkItem"/>&nbsp; Morning</td>
    <td><input type="checkbox" name="mon_afternoon" value="mon_morning" class="checkItem"/>&nbsp; Afternoon</td>
    <td><input type="checkbox" name="mon_evening" value="mon_evening" class="checkItem"/>&nbsp; Evening</td>
  </tr>
  <tr>
    <td><input type="checkbox" name="tue_morning" value="tue_morning" id="checkAll_1"/>&nbsp;<strong>TUE</strong></td>
    <td><input type="checkbox" name="tue_morning" value="tue_morning" class="checkItem_1"/>&nbsp; Morning</td>
    <td><input type="checkbox" name="tue_afternoon" value="tue_morning" class="checkItem_1"/>&nbsp; Afternoon</td>
    <td><input type="checkbox" name="tue_evening" value="tue_evening" class="checkItem_1"/>&nbsp; Evening</td>
  </tr>
  <tr>
    <td><input type="checkbox" name="wed_morning" value="wed_morning" id="checkAll_2"/>&nbsp;<strong>WED</strong></td>
    <td><input type="checkbox" name="wed_morning" value="wed_morning"/>&nbsp; Morning</td>
    <td><input type="checkbox" name="wed_afternoon" value="wed_morning"/>&nbsp; Afternoon</td>
    <td><input type="checkbox" name="wed_evening" value="wed_evening"/>&nbsp; Evening</td>
  </tr>
  <tr>
    <td><input type="checkbox" name="thu_morning" value="thu_morning" id="checkAll_3"/> <strong>THU</strong></td>
    <td><input type="checkbox" name="thu_morning" value="thu_morning"/>&nbsp; Morning</td>
    <td><input type="checkbox" name="thu_afternoon" value="thu_morning"/>&nbsp; Afternoon</td>
    <td><input type="checkbox" name="thu_evening" value="thu_evening"/>&nbsp; Evening</td>
  </tr>
  <tr>
    <td><input type="checkbox" name="fri_morning" value="fri_morning" id="checkAll_4"/> <strong>FRI</strong></td>
    <td><input type="checkbox" name="fri_morning" value="fri_morning"/>&nbsp; Morning</td>
    <td><input type="checkbox" name="fri_afternoon" value="fri_morning"/>&nbsp; Afternoon</td>
    <td><input type="checkbox" name="fri_evening" value="fri_evening"/>&nbsp; Evening</td>
  </tr>
  <tr>
    <td><input type="checkbox" name="sat_morning" value="sat_morning" id="checkAll_5"/> <strong>SAT</strong></td>
    <td><input type="checkbox" name="sat_morning" value="sat_morning"/>&nbsp; Morning</td>
    <td><input type="checkbox" name="sat_afternoon" value="sat_morning"/>&nbsp; Afternoon</td>
    <td><input type="checkbox" name="sat_evening" value="sat_evening"/>&nbsp; Evening</td>
  </tr>
  <tr>
    <td><input type="checkbox" name="sun_morning" value="sun_morning" id="checkAll_6"/> <strong>SUN</strong></td>
    <td><input type="checkbox" name="sun_morning" value="sun_morning"/>&nbsp; Morning</td>
    <td><input type="checkbox" name="sun_afternoon" value="sun_morning"/>&nbsp; Afternoon</td>
    <td><input type="checkbox" name="sun_evening" value="sun_evening"/>&nbsp; Evening</td>
  </tr>
</table>
if(isset($_POST['mon_morning'])) { $mon_morning = inputvalid($_POST['mon_morning']);}
if(isset($_POST['mon_afternoon'])) $mon_afternoon = inputvalid($_POST['mon_afternoon']);
if(isset($_POST['mon_evening'])) $mon_evening = inputvalid($_POST['mon_evening']); 
if(isset($_POST['tue_morning'])) $tue_morning = inputvalid($_POST['tue_morning']); 
// more.....
我用来选中一行内所有复选框的Javascript

<script>
$('td:first-child input[type="checkbox"]').on('change', function(){
    $(this)
    .closest('td')
    .siblings()
    .find('input[type="checkbox"]').prop('checked', this.checked);
});
</script>

$('td:first child input[type=“checkbox”]”)。在('change',function()上{
$(本)
.最近的('td')
.兄弟姐妹()
.find('input[type=“checkbox”]').prop('checked',this.checked);
});

未选中的复选框不会过帐。这就是为什么要用
isset()
选中此复选框,然后为复选框创建变量。但如果未选中复选框,则不会创建空变量。这就是为什么会得到一个变量未定义的通知

尝试将php代码更改为

if(isset($_POST['mon_morning'])) {
    $mon_morning = inputvalid($_POST['mon_morning']);
} else {
    $mon_morning = false;
}

什么是表单方法GET/POST?
isset
在这里不是一个很好的选项,因为如果提交了复选框但没有设置值,它也会返回false
array\u key\u exists
是一个更好、更可靠的选择。
Try this code:
if (isset($_POST['mon_morning']) && !empty($_POST['mon_morning'])) {
    $mon_morning = inputvalid($_POST['mon_morning']);
} else {
    $mon_morning = null;
}