Bonjour,
j'aimerais avoir de l'aide sur mon code parce que je n'arrive pas à inserer dans ma base de donnée.
voici le code
<html>
<head>
</head>
<body>
<?php
include("connexionbd.php");
?>
<form method="post" action="ajouter.php">
<table align="center" >
<tr>
<td>Type</td>
<td><select name="type">
<?php
$reponse=$bdd->query('SELECT * from types');
while($donnees=$reponse->fetch()) {
?>
<option value="<?php echo $donnees['id_type'];?>"><?php echo $donnees['type'];?></option>
<?
}
?>
</select></td>
</tr>
<tr>
<td>Nationalite</td>
<td><select name="nationalite">
<?php
$reponse1=$bdd->query('select * from nationalite');
while($donnees1=$reponse1->fetch()) {
?>
<option value="<?php echo $donnees1['id_nat'];?>"><?php echo $donnees1['nationalite'];?></option>
<?
}
?>
</select></td>
</tr>
<tr>
<tr>
<td>Titre</td>
<td><input type="text" name="titre" value=""/></td>
</tr>
<tr>
<td>Description</td>
<td><input type="text" name="description" value=""/></td>
</tr>
<tr>
<td>Lien Video</td>
<td><input type="text" name="lien" value=""/></td>
</tr>
<tr>
<td>Difficulte</td>
<td><input type="text" name="difficulte" value=""/></td>
</tr>
<tr>
<td>Etapes</td>
<td><textarea type="text" name="etapes" ></textarea></td>
</tr>
<tr>
<td>Ingredients</td>
<td><textarea name="ingredients" value="" ></textarea></td>
</tr>
<tr>
<td>Temps de preparation</td>
<td><input type="text" name="temps" value=""/></td>
</tr>
<tr>
<td>Nombre de personne</td>
<td><input type="text" name="nbre_pers" value=""/></td>
</tr>
<tr>
<td align="right"><input type="submit" name="valider" value="Enregistrer"/></td>
<td><input type="reset" name="anul" value="Recommencer"/></td>
</tr>
</table>
</form>
<?php
if(isset($_POST['valider'])){
//connexion à la base de donnée
try{
$bdd=new PDO('mysql:host=localhost;dbname=recettes','root','pisloven');
//verification de l'existence des variables
if(isset($_POST['type'])and
isset($_POST['nationalite'])and
isset($_POST['titre'])and
isset($_POST['description'])and
isset($_POST['lien'])and
isset($_POST['difficulte'])and
isset($_POST['etapes'])and
isset($_POST['ingredients'])and
isset($_POST['temps'])and
isset($_POST['nbre_pers'])
){
//affectation des valeurs aux variables
$titre=($_POST['titre']);
$description=($_POST['description']);
$lien=($_POST['lien']);
$difficulte=($_POST['difficulte']);
$etapes=($_POST['etapes']);
$ingredients=($_POST['ingredients']);
$temps=($_POST['temps']);
$nbre_pers=($_POST['nbre_pers']);
$type=($_POST['type']);
$nationalite=($_POST['nationalite']);
}
if(empty($_POST['type']) or
empty($_POST['nationalite']) or
empty($_POST['titre']) or
empty($_POST['description']) or
empty($_POST['lien']) or
empty($_POST['difficulte']) or
empty($_POST['etapes']) or
empty($_POST['ingredients']) or
empty($_POST['temps']) or
empty($_POST['nbre_pers'])) {
echo 'vous devez remplir tous les champs';
}
else {
//insertion dans la table plats
$req=$bdd->prepare('INSERT INTO plats(titre,description,lien,difficulte,etapes,ingredients,temps,nbre_pers,id_type,id_nat)VALUES
(:titre,:description,:lien,:difficulte,:etapes,:ingredients,:temps,:nbre_pers,:id_type,:id_nat)')or die(print_r($bdd->errorInfo()));
$req->execute(array('titre'=>$titre,
'description'=>$description,
'lien'=>$lien,
'difficulte'=>$difficulte,
'etapes'=>$etapes,
'ingredients'=>$ingredients,
'temps'=>$temps,
'nbre_pers'=>$nbre_pers,
'id_type'=>$type,
'id_nat'=>$nationalite
));
}
if($req) {
header('location:traitementfin.php');
}
else {
echo "insertion non effectuée";
}
}
catch(PDOException $e){
die('Erreur'.$e->getMessage());
}
}
?>
<a href="traitementfin.php">page principale</a>
</body>
</html>
Afficher la suite