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
| <?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 se connecte
require_once("connexion.php");
//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['nom0']) && !empty($_POST['nom1']) && !empty($_POST['nom2']) && !empty($_POST['nom3']) && !empty($_POST['nom4']) && !empty($_POST['nom5']) && !empty($_POST['nom6']))
{
$obj =new hotel($_POST['nom0'],$_POST['nom1'],$_POST['nom2'],$_POST['nom3'],$_POST['nom4'],$_POST['nom5'],$_POST['nom6']);
$obj->ajouter();
}
?> |
Partager