i'm a newbie in programming and still learning. I've created a database in mySQL to store a fictional restaurant's reservations. I got my site's form up and running, when you enter your info (email/seats needed/date/hour) it registers and is entered into the database successfully. But now i'm trying to check and see if i have double entries in my database to then send a message to my customer saying "sorry, that table is already booked, please choose another time or date"
just to make it simple, all i want to check for now is if the "seating table" in question is already in the database more than 2 times, if a third attempt is made i want to error message to appear, but i can't seem to figure out how to check my sql for that, here is the code i have for now... the column i'm checking is the seating table "5-8" people, my selections are 1-2, 3-4 and 5-8. 5-8 is what is written in the sql table column as "text"
require_once("config.php.inc");
$idConnexion = new mysqli($serveur, $utilisateur, $motDePasse, $bd, $port);
if ($idConnexion->connect_error) {
die('Erreur de connexion (' . $idConnexion->connect_errno . ') ' .$idConnexion->connect_error);
}
$requete = $idConnexion->query("SELECT * FROM tables") or die("La requete a echouee!");
$tableau = $requete->fetch_array();
$heure_res = $tableau["heure"];
$date_res = $tableau["date_res"];
$nombre_res = $tableau["nombre_personnes"];
if (($tableau = $requete->fetch_array()) !=FALSE) {
$nombre_table = $nombre_res == "5-8";
if (count($nombre_table) >= 2) {
echo "Il n'y a plus de place, choisissez une autre heure ou date.";
} else {
$resultats = $idConnexion->query("INSERT INTO `tables` SET email = '$_GET[email]', nombre_personnes ='$_GET[nombre_personne]', date_res = '$_GET[date_res]', heure = '$_GET[heure_preference]'") or die("La requête a échouée! : (" . $idConnexion->errno . ") " . $idConnexion->error);
$message = "L'ajout de la réservation a été fait avec succès!";
include("succes_interface.php");
}
}
once i fetch the array, i'm trying to see if the "5-8" is in the database more than twice, to return an error, and if it is less than 2, then PHP can continue and add the reservation into the database.
I really hope i'm asking the right questions, I have searched StackOverflow for an answer, but didn't have any luck.
Thank you in advance.