Hi im trying to learn vanilla PHP with PDO to load and edit mySQL database, I am trying to create an example of a form validation where a student selects which module they want and a lab session afterwards followed by their name and email.
I want to include a capacity to the form so if so many students choose lab session 2 and lab session 2 has a max capacity of 3 students, for example. Then that lab session is fully booked and the student cant sign up to the session if they do they get an error message to say the session is fully booked.
I attemped to do this and it seemed bad and messy, it also didnt work as eventhough it gave the error message to say the session is fully booked, it still inserts the data into mysql.
Part of my code below:
if (isset($_POST['submit'])){
if(filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)){
$module=$_POST['MODCOD'];//drop down menu
$lab=$_POST['LabTime'];//drop down menu student selects session they want
$first=$_POST['firstName'];//enter manually
$last=$_POST['lastName'];
$email=$_POST['email'];
echo '<p> user registered</p>';
echo "<h2>Lab booking table </h2>\n";
$checkLab517 =$pdo->query("select count(*) from meetings WHERE Lab='11:00, Lab 2'") ->fetchColumn();
$checkLab518 =$pdo->query("select count(*) from meetings WHERE Lab='11:00, Lab 3'") ->fetchColumn();
}
}
else{
echo 'Invalid';
}
if($checkLab517==3){
echo 'COMP517:<br>';
echo '11:00, Lab 2','<font color="red"> FULLY BOOKED</font><br>';
}
if($checkLab518==2){
echo 'COMP518:<br>';
echo '11:00, Lab 3','<font color="red"> FULLY BOOKED</font>';
}
else{
$sql = "INSERT INTO meetings (Module, Lab, Email,firstName,lastName)
VALUES ('$module', '$lab', '$email','$first','$last')";
$pdo->exec($sql);
}
Any help would be appreciated thanks for your time