@$fname=$_POST['fname'];
@$sex=$_POST['sex'];
@$month=$_POST['month'];
@$agree=$_POST['agree'];
We set a flag to status 'OK' and at the end we will see if the $status_form is changed or not, if any of the validation fails then this status will change to NOTOK. We will also crate a variable to store the message and at the beginning it is kept blank.
$status_form = "OK";// Set a flag to check
$msg=""; // Message variable
$row=array("t1"=>"T","r1"=>"T","r2"=>"T","s1"=>"T","c1"=>"T","msg"=>"","status_form"=>"OK");
We have created one array with all the element status setting to T or validation is passed. As we check one by one element , we will change the status to false and add failure message to it. if(strlen($fname) < 3){
$row["status_form"]="NOTOK";
$row["t1"]="F";
$msg .= "Your Name must be more than 3 char length<br>";
}
See that if the valdation is not OK then we are changing the $status_form and the message we are adding the respective elements of the array
Similar way we have checked that the user has selected one of the two radio button by checking the variable sex. User must select one of the month so we have checked the variable $month. Finally we can check the status of the checkbox by checking its value is set to yes or not. If all the validations passed then the status of variable $status is checked ( OK or NOTOK) and output is given in green color font or in red color font.
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.