I am trying to check three elements are already present in a database. The elements are room, timers and dates. I want to check if what I am entering is already present in the database groom. The below code compares what I am entering with what is already present and if its the same it tells me to enter different data, but if it is not it enters my data. The only problem is that it checks them individually rather than collectively and then it enters my data numerous times up until it notices that my data was in fact present and should not have been entered.
Is it possible to compare my entry with the data already present and then once all the data has been entered decide whether my data can be added rather than adding it every time it gets to if. Hopefully this question comes across clear and thank you in advance!!
$sql = "SELECT id, room, timers, dates FROM groom";
$result = $conn -> query ($sql);
if ($result -> num_rows >0){
while($row = $result -> fetch_assoc()){
if($room == $row["room"] AND $timers == $row["timers"] AND $dates == $row["dates"] ){
echo "This booking is not available";
}else{
//book
//here it books every time even though it has not checked all the data above in the if statement
}