Bonjour!
j'ai un problème avec une fonction que j'ai créée pour gérer de doublon.
Je voudrais respecter cette règle de gestion que j'ai élaboré: un même hôtel ne doit pas s'enregistrer deux fois dans une commune.
J'ai donc pris deux champs (nom de l’hôtel et commune) pour en faire une requête paramétrée.
Voici la fonction:fonctions.php
<?php
function doublon($nom, $id_commune) {
// Connexion à la base de données
try
{
$bdd = new PDO('mysql:host=localhost;dbname=test', 'root', '');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$requete $bdd->prepare("SELECT * FROM hotel WHERE nomhot :nom AND idcom = :id_commune");
$requete->bindValue(':nom', $nom);
$requete->bindValue(':id_commune', $id_commune);
$requete->execute();
$resultat = $requete->fetchAll();
return $resultat;
}
Voici la page enreg_hotel.php
<?php
$nom = (isset($_POST['nom'])) ? htmlspecialchars($_POST['nom']) : '';
?>
<form method="post">
<fieldset>
<legend>Enregistrement d'un hotel:</legend>
<label class="form_col" for="lastName">Nom* :</label>,
"/>,
----
<label class="form_col" for="com">Commune* :</label>,
<select id="com" name="com">
<option value="">-- Communes --</option>
<option value="1">Ouidah</option>
<option value="2">Cotonou</option>
<option value="3">Abomey-Calavi</option>
</select>
</fieldset>
</form>
<?php
extract($_POST);
if (isset($ok))
{
//echo $nom.$com;
include 'fonctions.php';
$trouve = doublon($nom, $com);
if ($trouve > 0)
{
echo "Cet hotèl est déjà enregistré dans cette commune.";
}
else
{
echo "Vous pouvez continuer.";
}
}
ça ne marche pas. ça me renvoi s'il y a doublon ou pas ceci: Cet hotèl est déjà enregistré dans cette commune
Veuillez m'aider.
Voici la bdd:
CREATE TABLE IF NOT EXISTS `hotel` (
`idhot` int(11) NOT NULL AUTO_INCREMENT,
`nomhot` varchar(150) NOT NULL,
`iddep` int(11) NOT NULL,
`idcom` int(11) NOT NULL,
`quarthot` varchar(50) NOT NULL,
`bphot` varchar(10) NOT NULL,
`emailhot` varchar(100) NOT NULL,
`fixhot` varchar(50) NOT NULL,
`mobhot` varchar(50) NOT NULL,
`faxhot` varchar(50) NOT NULL,
`photohot` varchar(128) NOT NULL DEFAULT '',
`reperhot` text NOT NULL,
`descriphot` text NOT NULL,
`autrehot` text NOT NULL,
`standhot` varchar(10) NOT NULL,
`prixbashot` int(11) NOT NULL,
`prixhauhot` int(11) NOT NULL,
`adminhot` varchar(50) NOT NULL,
`pwdhot` char(50) NOT NULL,
`idres` int(11) NOT NULL,
`idpha` int(11) NOT NULL,
`idbank` int(11) NOT NULL,
`idsup` int(11) NOT NULL,
`idcab` int(11) NOT NULL,
`idagv` int(11) NOT NULL,
`actif` tinyint(1) NOT NULL,
`hash_validation` char(32) NOT NULL,
PRIMARY KEY (`idhot`),
UNIQUE KEY `emailhot` (`emailhot`),
KEY idcom (idcom)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
INSERT INTO `hotel` (`idhot`, `nomhot`, `iddep`, `idcom`, `quarthot`, `bphot`, `emailhot`, `fixhot`, `mobhot`, `faxhot`, `photohot`, `reperhot`, `descriphot`, `autrehot`, `standhot`, `prixbashot`, `prixhauhot`, `adminhot`, `pwdhot`, `idres`, `idpha`, `idbank`, `idsup`, `idcab`, `idagv`, `actif`, `hash_validation`) VALUES
(1, 'Jango Hotel', 1, 1, 'Toffi', '', 'jango@yahoo.fr', '', '', '', 'images/avatars/1.png', '', '', '', '', 0, 0, 'Jango', '3fd82ed20452be5eaff316f4c0fe753fe63a5074', 0, 0, 0, 0, 0, 0, 0, 'f855049df6357f9e5dcdf9765a2a41a8');
Afficher la suite