getMessage(); } // Vérifier si le formulaire a été soumis if ($_SERVER['REQUEST_METHOD'] === 'POST') { $numero_appart = $_POST['numero_appart']; $nom_locataire = $_POST['nom_locataire']; // Vérifier si l'appartement existe déjà dans la table $stmt = $pdo->prepare('SELECT COUNT(*) FROM appartements WHERE numero_appart = ?'); $stmt->execute([$numero_appart]); $count = $stmt->fetchColumn(); if ($count > 0) { echo 'L\'appartement existe déjà.'; } else { // Insérer l'appartement dans la table $stmt = $pdo->prepare('INSERT INTO appartements (numero_appart, nom_locataire) VALUES (?, ?)'); $stmt->execute([$numero_appart, $nom_locataire]); echo 'L\'appartement a été ajouté avec succès.'; } } ?>
L'appartement numéro " . $numero_appart . " existe déjà.
"; } else { // Insert the form data into the database $sql_insert = "INSERT INTO appartements (numero_appart, nom_locataire) VALUES ('$numero_appart', '$nom_locataire')"; if ($conn->query($sql_insert) === TRUE) { echo "L'appartement a été ajouté avec succès.
"; } else { echo "Error: " . $sql_insert . "