Formulaire php vers base MySQL
Résolu/Fermé
A voir également:
- Formulaire php vers base MySQL
- Formulaire de réclamation facebook - Guide
- Base de registre - Guide
- Easy php - Télécharger - Divers Web & Internet
- Mysql community server - Télécharger - Bases de données
- Formulaire de reclamation instagram - Guide
2 réponses
Alain_42
Messages postés
5361
Date d'inscription
dimanche 3 février 2008
Statut
Membre
Dernière intervention
13 février 2017
894
24 mai 2012 à 13:50
24 mai 2012 à 13:50
pourquoi tu t'embêtes avec des name= ....[] sous forme d'array quand ce n'est pas indispensable
surtout si ensuite tu récupères la valeur comme tu as fait par une boucle qui ne garde que la dernière de l'array
surtout si ensuite tu récupères la valeur comme tu as fait par une boucle qui ne garde que la dernière de l'array
<?php $server="localhost"; $user="root"; $pwd=""; $conn=@mysql_connect($server,$user,$pwd); If ($conn == FALSE) { die ("connexion impossible<br/>"); } //SELECTION DE LA BASE DE DONNEES $bdd="gestionbase"; $connect_base = @mysql_select_db($bdd); If ($connect_base == FALSE) { die ("Sélection BASE Impossible<br/>"); } //INSERE LES DONNEES DE LA BASE if(isset($_POST['save'])) //ce test c'est pour que PHP attende le clic sur enregistrer { $matricule=mysql_real_escape_string($_POST["matricule"]); $name=mysql_real_escape_string($_POST["nom"]); $prename=mysql_real_escape_string($_POST["prenom"]); $email=mysql_real_escape_string($_POST["mail"]); $pass=mysql_real_escape_string($_POST["pass"]); $mind_profil=mysql_real_escape_string($_POST["profil"]); $mind_cod=mysql_real_escape_string($_POST["code"]); $qualif=mysql_real_escape_string($_POST["qualification"]); $tel=mysql_real_escape_string($_POST["telphone"]); if(empty($matricule)) { echo"<script type=\"text/javascript\">" ; echo "alert('Veuillez renseigner les champs sont obligatoires s\'il vous plaît !');"; echo "</script>"; } else { $sql = "INSERT INTO agent (matricule_agent, nom_agent, prenom_agent, qualification, email, motdepasse, num_tel, code_bureau, code_profil) values ('$matricule', '$name', '$prename', '$qualif', '$email', '$pass', '$tel', '$mind_cod', '$mind_profil')"; $insert=mysql_query ($sql, $conn); if($insert){ header('Location: succes.html'); }else{ echo "Pb lors de l'insertion BDD !"; } } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Connexion | KVIK ProductionS</title> </head> <body style="margin:30px; font-family:Geneva, Arial, Helvetica, sans-serif"> <center> <form method="post" name="inscrire_agent" action="Enregistrement_Agent.php" style="width:500px;"> <fieldset style="text-align:left"> <legend><b>Vos coordonnées</b></legend> <table> <tr> <td width="150"> <b>Matricule * : </b> </td> <td width="200"> <div align="justify"> <input name="matricule" type="text" maxlength="50" /> </div></td> </tr> <tr> <td width="150"> <b>Nom : </b> </td> <td width="200"> <div align="justify"> <input name="nom" type="text" maxlength="50" /> </div></td> </tr> <tr> <td width="150"> <b>Prénom : </b> </td> <td width="200"> <div align="justify"> <input name="prenom" type="text" maxlength="50" /> </div></td> </tr> <tr> <td width="150"> <b>Email : </b> </td> <td width="200"> <div align="justify"> <input name="mail" type="text" maxlength="50" /> </div></td> </tr> <tr> <td width="150"> <b>Mot de passe : </b> </td> <td width="200"> <div align="justify"> <input name="pass" type="password" maxlength="20" /> </div></td> </tr> <tr> <td width="150"> <b>Code Profil : </b> </td> <td width="200"> <div align="justify"> <select name="profil" style="width:150px"> <?php $ssql = "SELECT * FROM profil"; $result = mysql_query ($ssql); while ($row = mysql_fetch_object($result)) { if ($row->code_profil==$code_profil_int) {$selected="selected";} else {$selected="";} echo "<option value='$row->code_profil' $selected>$row->code_profil -- $row->libelle_profil</option>"; } ?> </select> </div></td> </tr> <tr> <td width="150"> <b>Qualification : </b> </td> <td width="200"> <div align="justify"> <input name="qualification" type="text" maxlength="50" /> </div></td> </tr> <tr> <td width="150"> <b>Code bureau : </b> </td> <td width="200"> <div align="justify"> <select name="code" style="width:150px"> <?php $ssql = "select * from bureau"; $result = mysql_query ($ssql); while ($row = mysql_fetch_object($result)) { if ($row->code_bureau==$code_bureau_int) {$selected="selected";} else {$selected="";} echo "<option value='$row->code_bureau' $selected>$row->code_bureau -- $row->libelle_bureau</option>"; } ?> </select> </div></td> </tr> <tr> <td width="150"> <b>Téléphone : </b> </td> <td width="200"> <div align="justify"> <input name="telphone" type="text" maxlength="20" /> </div></td> </tr> </table> </fieldset> <br/> <table width="100%"> <tr align="center"> <td width="130" align="center"> <input type="submit" name="save" value="Enregistrer" /> </td> <td width="130" align="center"> <input type="reset" name="efface" value="Annuler" /> </td> </tr> </table> </form> </center> </body> </html>