我在php中验证html表单,我想打印出空字段的键,
$url = $_POST['url']; $start_time = $_POST['start_time']; $end_time = $_POST['end_time'];
$arr = array("Url"=>"$url","Start Time"=>"$start_time","End Time"=> "$end_time");
答案 0 :(得分:0)
而不是......
$url = $_POST['url']; $start_time = $_POST['start_time'];
$end_time = $_POST['end_time'];
我建议
$err =0;
// repeat following block for every mandatory input
if ((isset($_POST['url']) && (!empty($_POST['url']))){
$url = $_POST['url'];
} else {$err++; $errmsg .='You need to enter a URL<br>';}
...
if ($err > 0){
echo $errmsg;
} else {
// process submitted form
}
例如,在使用用户提供的变量做任何事情之前,我更愿意先查找错误。