In code below it is suppose to contains all the errors in an array and then display the errors in one depening on which errors are activated. But problem is that it is still displaying the errors only one at a time, it is not displaying att the relevant errors at once. What do I need to change in order to do this?
$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];
}
}
Try a solution like this:
I do not see a variable set for $numrows, if this is set elsewhere; then ignore this. Otherwise, I would review your code.
I would also take a few pointers on your codes presentation