Insertion dans la base de donnée

Par fleur, il y a 10 ans


Bonsoir, je fais une requête pour ajouter des données dans ma base de donnée
il m'affiche aucune erreur, mais rien n'est inséré dans la base de donnée
j'espere que quelqu'un pourra m'aider :s :s
voila mon code (ajouteretudiant.php)

<link type="text/css" href="./css/style.css" rel="stylesheet" /> <?php require_once("connect.php");?> <?php $reponse=$bdd->prepare('INSERT INTO etudiant (nom,prenom,date_de_naissance,email,choix1,numero_inscription,NIVEAU,choix2,choix3,choix4) VALUES(:nom,:prenom,:date_de_naissance,:email,:choix1,:numero_inscription,:NIVEAU,:choix2,:choix3,:choix4)'); $reponse->execute(array( 'nom'=>$_POST['nom'], 'prenom'=>$_POST['prenom'], 'date_de_naissance'=>$_POST['date_de_naissance'], 'email'=>$_POST['email'], 'choix1'=>$_POST['choix1'], 'NIVEAU'=>$_POST['NIVEAU'], 'numero_inscription'=>$_POST['numero_inscription'], 'choix2'=>$_POST['choix2'], 'choix3'=>$_POST['choix3'], 'choix4'=>$_POST['choix4'])); echo"etudiant ajouté"; ?>

et ajouter.html

<html> <head> <title></title> <link type="text/css" href="./css/style.css" rel="stylesheet" /> <head> <body> <fieldset border="1"> <legend> Fiche Etudiant </legend> <form method="POST" action="ajouteretudiant.php"> <?php if (isset($_POST['nom'])) { $nom = $_POST['nom']; } if (isset($_POST['prenom'])) { $nom = $_POST['prenom']; } if (isset($_POST['date_de_naissance'])) { $date_de_naissance=$_POST['date_de_naissance']; } if (isset($_POST['email'])) { $email=$_POST['email']; } if (isset($_POST['choix1'])) { $choix1=$_POST['choix1']; } if (isset($_POST['numero_inscription'])) { $numero_inscription=$_POST['numero_inscription']; } if (isset($_POST['NIVEAU'])) { $NIVEAU=$_POST['NIVEAU']; } if (isset($_POST['choix2'])) { $choix2=$_POST['choix2']; } if (isset($_POST['choix3'])) { $choix3=$_POST['choix3']; } if (isset($_POST['choix4'])) { $choix4=$_POST['choix4']; } ?> <table> <tr> <td> NOM:</td> <td><input type="text" name="nom"/></td> </tr> <tr> <td>PRENOM:</td> <td><input type="text" name="prenom"/></td> </tr> <tr> <td>DATE_DE_NAISSANCE:</td> <td><input type="date" name="date_de_naissance"/></td> </tr> <tr> <td>EMAIL:</td> <td><input type="text" name="email"/></td> </tr> <tr> <td>CHOIX1:</td> <td><input type="text" name="choix1"/></td> </tr> <tr> <td>NUMERO_INSCRIPTION:</td> <td><input type="text" name="numero_inscription"/></td> </tr> <tr> <td>NIVEAU:</td> <td><input type="text" name="NIVEAU"/></td> </tr> <tr> <td>CHOIX2:</td> <td><input type="text" name="choix2"/></td> </tr> <tr> <td>CHOIX3:</td> <td><input type="text" name="choix3"/></td> </tr> <tr> <td>CHOIX4:</td> <td><input type="text" name="choix4"/></td> </tr> <tr> <td><input type="submit" value="enregistrer" action="ajouteretudiant.php"/></td> </tr> </table> </form> </fieldset> </body> </html>

MERCI.

4 réponses

Alexandre #lbac, il y a 10 ans

ajouter.html alors que le code contient du php ?

Ensuite inutile de définitir un attribut action à ta balise input type="submit"

Carouge10, il y a 10 ans

Bonjour,

Que donne le var_dump de $_POST et faite aussi un var_dump de la réponse de la requête :

$resultat = $reponse->execute(array( 'nom'=>$_POST['nom'], 'prenom'=>$_POST['prenom'], 'date_de_naissance'=>$_POST['date_de_naissance'], 'email'=>$_POST['email'], 'choix1'=>$_POST['choix1'], 'NIVEAU'=>$_POST['NIVEAU'], 'numero_inscription'=>$_POST['numero_inscription'], 'choix2'=>$_POST['choix2'], 'choix3'=>$_POST['choix3'], 'choix4'=>$_POST['choix4'])); var_dump($resultat);
betaWeb, il y a 10 ans

Salut, tu peux raccourcir ta query substentiellement de cette façon :

$resultat = $reponse->execute($_POST);
fleur, il y a 10 ans

Merci pour vos reponse, sa maidera la prochaine fois :D , Mais enfin de compte j'avais tout simplement oublié un champ, une fois que je l'ai ajouté.je peux donc ajouter des etudiants. Merci à vous.