1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
<?php
//On se connecte
require_once("connexion.php");
class hotel{
public $Nomhotel;
public $Adresse;
public $Pays;
public $Ville;
public $Téléphone;
public $Fax;
public $Catégorie;
function __construct($Nomhotel,$Adresse,$Pays,$Ville,$Téléphone,$Fax,$Catégorie){
$this->Nomhotel =$Nomhotel;
$this->Adresse =$Adresse;
$this->Pays =$Pays;
$this->Ville =$Ville;
$this->Téléphone =$Téléphone;
$this->Fax =$Fax;
$this->Catégorie =$Catégorie;
}
//On récupère les valeurs entrées par l'utilisateur :
public function ajouter(){
//On prépare la commande sql d'insertion
$sql = 'INSERT INTO hotel VALUES("'.$this->Nomhotel.'","'.$this->Adresse.'","'.$this->Pays.'","'.$this->Ville.'","'.$this->Téléphone.'","'.$this->Fax.'","'.$this->Catégorie.'")';
/*on lance la commande (mysql_query) et au cas où,
on rédige un petit message d'erreur si la requête ne passe pas (or die)
(Message qui intègrera les causes d'erreur sql)*/
mysql_query ($sql) or die ('Erreur SQL !'.$sql.'<br />'.mysql_error());
}
}
if (!empty($_POST['Nomhotel']) && !empty($_POST['Adresse']) && !empty($_POST['Pays']) && !empty($_POST['Ville']) && !empty($_POST['Téléphone']) && !empty($_POST['Fax']) && !empty($_POST['Catégorie']))
{
$obj =new hotel($_POST['Nomhotel'],$_POST['Adresse'],$_POST['Pays'],$_POST['Ville'],$_POST['Téléphone'],$_POST['Fax'],$_POST['Catégorie']);
$obj->ajouter();
}
elseif (!empty($_POST['Nomhotel']) || !empty($_POST['Adresse']) || !empty($_POST['Pays']) || !empty($_POST['Ville']) || !empty($_POST['Téléphone']) || !empty($_POST['Fax']) || !empty($_POST['Catégorie']))
{
echo "veuillez remplir tous les champs svp";
}
elseif($Nomhotel != $_POST['Nomhotel'])
{
echo "le nom d'hotel existe déjà";
}
?> |
Partager