Eléphant du PHP |
167 Messages
24 mai 2013, 11:23
Voici les codes :
<form name="ajout" action="formation.php" method="POST">
<table>
<tr>
<td><label for="id_formateur"><strong>Formateur :</strong></label></td>
<td><form><select name="id_formateur">
<?php
require("connect.php");
$dsn="mysql:dbname=".BASE.";host=".SERVER;
try{
$connexion=new PDO($dsn,USER,PASSWD);
}
catch(PDOException $e){
printf("Échec de la connexion : %s\n", $e->getMessage());
exit();
}
$requete="SELECT * FROM formateur";
if(!$connexion->query($requete)) echo "Pb d'accès à la table";
else{
foreach ($connexion->query($requete) as $row){
echo "<option value=".$row['id_formateur'].">".$row['nomformateur']."</option>";}
}
?>
</select></td></tr></form>
<tr>
<td><label for="idtype"><strong>Activité :</strong></label></td>
<td><form ><select name="idtype">
<option value="1" >Formation 1</option>
<option value="2" >Formation 2</option>
</select></td></tr></form>
formation.php
$nomform=isset($_POST['nomform'])?$_POST['nomform]:"";
$id_formateur=isset($_POST['id_formateur'])?$_POST['id_formateur]:"";
$idtype=isset($_POST['idtype'])?$_POST['idtype']:"";
$sql= "INSERT INTO formation (`id_form`, `nomform`, `idtype`,`id_formateur`) VALUES (' ', '$nomform', '$idtype','$id_formateur')";
$requete = mysql_query($sql) or die( mysql_error() ) ;