在下面的代码中,它假设包含一个数组中的所有错误,然后根据激活的错误显示错误。但问题是它仍然一次只显示一个错误,而不是一次显示相关错误。为了做到这一点,我需要改变什么?
$errors = array();
if (!$getcourseid){
$errors[] = "You must enter in Course's ID";
}else if (!$getcoursename){
$errors[] = "You must enter in Course's Name";
}else if (!$getduration){
$errors[] = "You must select Course's Duration";
}
if(empty($errors)) {
if ($numrows == 1){
$errormsg = "<span style='color: green'>Course " . $getcourseid . " - " . $getcoursename . " has been Created</span>";
$getcourseid = "";
$getcoursename = "";
$getduration = "";
}else{
$errormsg = "An error has occured, Course has not been Created";
}
} else {
if(isset($errors[0])) {
$errormsg = $errors[0];
} elseif (isset($errors[1])) {
$errormsg = $errors[1];
} elseif (isset($errors[1])) {
$errormsg = $errors[1];
}
}