Probleme denregistrement dans ma base mysql
westzinzin
-
Ozimandias Messages postés 528 Statut Membre -
Ozimandias Messages postés 528 Statut Membre -
Bonjour ,je suis un debutant en php et je me perd depuis 10 jours je narriv pas a enregistrer les donnees saisi dans ma tables mysql.
voici le code que jai ecri.
<?php require_once('Connections/Connect.php'); ?>
<?php
mysql_select_db($database_Connect, $Connect);
$query_Recordset1 = "SELECT id_ele, nom_ele, pre_ele FROM electeur ORDER BY id_ele DESC";
$Recordset1 = mysql_query($query_Recordset1, $Connect) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<title>Commission Electorale Nationale Autonome : formulaire d'enregistrement des électeurs </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style>
#moncadre {
width:900px;
margin:auto;
padding:10px;
background-color:#FFFF00;
border-left:1px solid #000000; /* couleur du cadre */
border-right:1px solid #000000;
border-bottom:1px solid #000000;
border-top:1px solid #000000;
}
#aff {
position: absolute;
width:450px;
margin:auto;
padding:10px;
background-color:#FFFF00;
border-left:1px solid #000000; /* couleur du cadre */
border-right:1px solid #000000;
border-bottom:1px solid #000000;
border-top:1px solid #000000;
left: 157px;
top: 221px;
height: 580px;
}
#affi {
position: absolute;
width:415px;
margin:500px;
padding:10px;
background-color:#FFFF00;
border-left:1px solid #000000; /* couleur du cadre */
border-right:1px solid #000000;
border-bottom:1px solid #000000;
border-top:1px solid #000000;
left: 175px;
top: -280px;
height: 580px;
}
</style>
</head>
<body TEXT="#000000" LINK="#FFFFFF" VLINK="#00AAFF">
<?php
if (isset($_POST['nom_ele']) AND isset($_POST['pre_ele']) AND isset($_POST['sexe_ele']) AND isset($_POST['lieu_nais_ele']) AND isset($_POST['profession']) AND isset($_POST['date_nais_ele']) AND isset($_POST['addresse_ele']) AND isset($_POST['num_ci_ele']) AND isset($_POST['tel_ele'])) // Si les variables existent
{
if ($_POST['nom_ele'] != NULL AND $_POST['pre_ele'] != NULL AND $_POST['sexe_ele'] != NULL AND $_POST['date_nais_ele'] != NULL AND $_POST['profession'] != NULL AND $_POST['lieu_nais_ele'] != NULL AND $_POST['addresse_ele'] != NULL AND $_POST['tel_ele'] != NULL AND $_POST['num_ci_ele'] != NULL ) // Si on a quelque chose à enregistrer
{
// D'abord, on se connecte à MySQL
mysql_connect("localhost", "root");
mysql_select_db("elections");
//mysql_select_db($database_Connect, $Connect);
// On utilise les fonctions PHP mysql_real_escape_string et htmlspecialchars pour la sécurité
$nom = mysql_real_escape_string(htmlspecialchars($_POST['nom_ele']));
$prenom = mysql_real_escape_string(htmlspecialchars($_POST['pre_ele']));
$sexe = mysql_real_escape_string(htmlspecialchars($_POST['sexe_ele']));
$datedenaissance = mysql_real_escape_string(htmlspecialchars($_POST['date_nais_ele']));
$lieudenaissance = mysql_real_escape_string(htmlspecialchars($_POST['lieu_nais_ele']));
$profession = mysql_real_escape_string(htmlspecialchars($_POST['profession']));
$addresse = mysql_real_escape_string(htmlspecialchars($_POST['addresse_ele']));
$telephone = mysql_real_escape_string(htmlspecialchars($_POST['tel_ele']));
$numpieceid = mysql_real_escape_string(htmlspecialchars($_POST['num_ci_ele']));
// Ensuite on enregistre l'électeur
mysql_query("INSERT INTO electeur(id_ele,nom_ele,pre_ele,) VALUES('', '$nom', '$prenom')");
// On se déconnecte de MySQL
mysql_close();
}
}
// Que l'on ait enregistré des données ou pas...
// On affiche le formulaire puis les 10 derniers messages
// Tout d'abord le formulaire :
?>
<h2><center> Formulaire d'enregistrement des électeurs </center></h2>
<center>
<div id="moncadre">
<table width="881" border="0">
<tr>
<td width="208"><strong>Département : </strong></td>
<td width="217"><input type="text" name="nom62" size="36" /></td>
<td width="212"><strong>Arrondissement : </strong></td>
<td width="216"><input type="text" name="nom624" size="36" /></td>
</tr>
<tr>
<td><strong>Commune : </strong></td>
<td><input type="text" name="nom622" size="36" /></td>
<td><strong>Village ou quartier de ville : </strong></td>
<td><input type="text" name="nom625" size="36" /></td>
</tr>
<tr>
<td><strong>Poste de recensement : </strong></td>
<td><input type="text" name="nom623" size="36" /></td>
<td><strong>Nom du responsable : </strong></td>
<td><input type="text" name="nom626" size="36" /></td>
</tr>
</table>
</div>
</center>
<p> </p>
<div id="aff">
<table width="430" height="539" border="0">
<form action = "enregtest.php" method="post">
<tr>
<td width="424" height="267"><fieldset>
<legend><strong>Etat Civil</strong></legend>
<table width="421" height="62" border="0">
<tr>
<td width="177">Nom : </td>
<td width="224"><input type="text" name="nom_ele" size="38" /></td>
</tr>
<tr>
<td>Prenom : </td>
<td><input type="text" name="pre_ele" size="38"/></td>
</tr>
</table>
<table width="421" height="30" border="0">
<tr>
<td width="104">Sexe : </td>
<td width="145"><input name="Masculin" type="radio" value="" />
Masculin</td>
<td width="145"><input name="Féminin" type="radio" value="" />
Féminin</td>
</tr>
</table>
<table width="421" height="30" border="0">
<tr>
<td width="140">Date de Naissance :</td>
<td width="265"><select name="date" >
<option value="choix1">1</option>
<option value="choix2">2</option>
<option value="choix3">3</option>
<option value="choix4">4</option>
<option value="choix5">5</option>
<option value="choix6">6</option>
<option value="choix7">7</option>
<option value="choix8">8</option>
<option value="choix9">9</option>
<option value="choix10">10</option>
<option value="choix11">11</option>
<option value="choix12">12</option>
<option value="choix13">13</option>
<option value="choix14">14</option>
<option value="choix15">15</option>
<option value="choix16">16</option>
<option value="choix17">17</option>
<option value="choix18">18</option>
<option value="choix19">19</option>
<option value="choix20">20</option>
<option value="choix21">21</option>
<option value="choix22">22</option>
<option value="choix23">23</option>
<option value="choix24">24</option>
<option value="choix25">25</option>
<option value="choix26">26</option>
<option value="choix27">27</option>
<option value="choix28">28</option>
<option value="choix29">29</option>
<option value="choix30">30</option>
<option value="choix31">31</option>
</select>
<select name="Mois">
<option value="Mois1">Janvier</option>
<option value="Mois2">Février</option>
<option value="Mois3">Mars</option>
<option value="Mois4">Avril</option>
<option value="Mois5">Mai</option>
<option value="Mois6">Juin</option>
<option value="Mois7">Juillet</option>
<option value="Mois8">Aout</option>
<option value="Mois9">Septembre</option>
<option value="Mois10">Octobre</option>
<option value="Mois11">Novembre</option>
<option value="Mois12">Décembre</option>
</select>
<select name="select">
<option value="An">1900</option>
<option value="An1">1901</option>
</select>
<br />
(Jour / Mois / Année)</td>
</tr>
</table>
<table width="421" height="30" border="0">
<tr>
<td width="177">Lieu de Naissance : </td>
<td width="224"><input type="text" name="nom3" size="38" /></td>
</tr>
</table>
<table width="421" height="62" border="0">
<tr>
<td width="177">Profession :</td>
<td width="224"><input type="text" name="professio," size="38" /></td>
</tr>
<tr>
<td>Addresse : </td>
<td><input type="text" name="addresse_ele" size="38" /></td>
</tr>
<tr>
<td>Carte d'identité N° : </td>
<td><input type="text" name="num_ci_ele" size="38" /></td>
</tr>
</table>
</fieldset></td>
</tr>
<tr>
<td width="424" height="265"><fieldset>
<legend><strong>Empreinte digitale</strong></legend>
<table width="421" height="208" border="0">
<tr>
<td width="201" height="202"><fieldset>
<table width="200" border="0">
<tr>
<td height="190"> </td>
</tr>
</table>
</fieldset></td>
<td width="204"><center>
<input type="submit" name="Submit" value="Capturer l'empreinte" id="Submit" />
</center></td>
</tr>
</table>
<table width="420" border="0">
<tr>
<td width="410"><center >
<input type="submit" name="Submit" value="Enregistrer les informations" id="Submit" />
</center></td>
</tr>
</table>
</fieldset></td>
</tr>
</form>
</table>
</div>
<div id="affi">
<center> <h4>Affichage des électeurs déjà enregistrés</h4>
<hr />
<table width= "400" border="1">
<tr>
<td width="50"><strong>Numéro</strong></td>
<td width="120"><strong>Nom</strong></td>
<td width="160"><strong>Prénoms</strong></td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_Recordset1['id_ele']; ?></td>
<td><?php echo $row_Recordset1['nom_ele']; ?></td>
<td><?php echo $row_Recordset1['pre_ele']; ?></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
<p> </p>
</center>
</div>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
AIDEZ MOI SIL VOUS PLAIT
voici le code que jai ecri.
<?php require_once('Connections/Connect.php'); ?>
<?php
mysql_select_db($database_Connect, $Connect);
$query_Recordset1 = "SELECT id_ele, nom_ele, pre_ele FROM electeur ORDER BY id_ele DESC";
$Recordset1 = mysql_query($query_Recordset1, $Connect) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<title>Commission Electorale Nationale Autonome : formulaire d'enregistrement des électeurs </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style>
#moncadre {
width:900px;
margin:auto;
padding:10px;
background-color:#FFFF00;
border-left:1px solid #000000; /* couleur du cadre */
border-right:1px solid #000000;
border-bottom:1px solid #000000;
border-top:1px solid #000000;
}
#aff {
position: absolute;
width:450px;
margin:auto;
padding:10px;
background-color:#FFFF00;
border-left:1px solid #000000; /* couleur du cadre */
border-right:1px solid #000000;
border-bottom:1px solid #000000;
border-top:1px solid #000000;
left: 157px;
top: 221px;
height: 580px;
}
#affi {
position: absolute;
width:415px;
margin:500px;
padding:10px;
background-color:#FFFF00;
border-left:1px solid #000000; /* couleur du cadre */
border-right:1px solid #000000;
border-bottom:1px solid #000000;
border-top:1px solid #000000;
left: 175px;
top: -280px;
height: 580px;
}
</style>
</head>
<body TEXT="#000000" LINK="#FFFFFF" VLINK="#00AAFF">
<?php
if (isset($_POST['nom_ele']) AND isset($_POST['pre_ele']) AND isset($_POST['sexe_ele']) AND isset($_POST['lieu_nais_ele']) AND isset($_POST['profession']) AND isset($_POST['date_nais_ele']) AND isset($_POST['addresse_ele']) AND isset($_POST['num_ci_ele']) AND isset($_POST['tel_ele'])) // Si les variables existent
{
if ($_POST['nom_ele'] != NULL AND $_POST['pre_ele'] != NULL AND $_POST['sexe_ele'] != NULL AND $_POST['date_nais_ele'] != NULL AND $_POST['profession'] != NULL AND $_POST['lieu_nais_ele'] != NULL AND $_POST['addresse_ele'] != NULL AND $_POST['tel_ele'] != NULL AND $_POST['num_ci_ele'] != NULL ) // Si on a quelque chose à enregistrer
{
// D'abord, on se connecte à MySQL
mysql_connect("localhost", "root");
mysql_select_db("elections");
//mysql_select_db($database_Connect, $Connect);
// On utilise les fonctions PHP mysql_real_escape_string et htmlspecialchars pour la sécurité
$nom = mysql_real_escape_string(htmlspecialchars($_POST['nom_ele']));
$prenom = mysql_real_escape_string(htmlspecialchars($_POST['pre_ele']));
$sexe = mysql_real_escape_string(htmlspecialchars($_POST['sexe_ele']));
$datedenaissance = mysql_real_escape_string(htmlspecialchars($_POST['date_nais_ele']));
$lieudenaissance = mysql_real_escape_string(htmlspecialchars($_POST['lieu_nais_ele']));
$profession = mysql_real_escape_string(htmlspecialchars($_POST['profession']));
$addresse = mysql_real_escape_string(htmlspecialchars($_POST['addresse_ele']));
$telephone = mysql_real_escape_string(htmlspecialchars($_POST['tel_ele']));
$numpieceid = mysql_real_escape_string(htmlspecialchars($_POST['num_ci_ele']));
// Ensuite on enregistre l'électeur
mysql_query("INSERT INTO electeur(id_ele,nom_ele,pre_ele,) VALUES('', '$nom', '$prenom')");
// On se déconnecte de MySQL
mysql_close();
}
}
// Que l'on ait enregistré des données ou pas...
// On affiche le formulaire puis les 10 derniers messages
// Tout d'abord le formulaire :
?>
<h2><center> Formulaire d'enregistrement des électeurs </center></h2>
<center>
<div id="moncadre">
<table width="881" border="0">
<tr>
<td width="208"><strong>Département : </strong></td>
<td width="217"><input type="text" name="nom62" size="36" /></td>
<td width="212"><strong>Arrondissement : </strong></td>
<td width="216"><input type="text" name="nom624" size="36" /></td>
</tr>
<tr>
<td><strong>Commune : </strong></td>
<td><input type="text" name="nom622" size="36" /></td>
<td><strong>Village ou quartier de ville : </strong></td>
<td><input type="text" name="nom625" size="36" /></td>
</tr>
<tr>
<td><strong>Poste de recensement : </strong></td>
<td><input type="text" name="nom623" size="36" /></td>
<td><strong>Nom du responsable : </strong></td>
<td><input type="text" name="nom626" size="36" /></td>
</tr>
</table>
</div>
</center>
<p> </p>
<div id="aff">
<table width="430" height="539" border="0">
<form action = "enregtest.php" method="post">
<tr>
<td width="424" height="267"><fieldset>
<legend><strong>Etat Civil</strong></legend>
<table width="421" height="62" border="0">
<tr>
<td width="177">Nom : </td>
<td width="224"><input type="text" name="nom_ele" size="38" /></td>
</tr>
<tr>
<td>Prenom : </td>
<td><input type="text" name="pre_ele" size="38"/></td>
</tr>
</table>
<table width="421" height="30" border="0">
<tr>
<td width="104">Sexe : </td>
<td width="145"><input name="Masculin" type="radio" value="" />
Masculin</td>
<td width="145"><input name="Féminin" type="radio" value="" />
Féminin</td>
</tr>
</table>
<table width="421" height="30" border="0">
<tr>
<td width="140">Date de Naissance :</td>
<td width="265"><select name="date" >
<option value="choix1">1</option>
<option value="choix2">2</option>
<option value="choix3">3</option>
<option value="choix4">4</option>
<option value="choix5">5</option>
<option value="choix6">6</option>
<option value="choix7">7</option>
<option value="choix8">8</option>
<option value="choix9">9</option>
<option value="choix10">10</option>
<option value="choix11">11</option>
<option value="choix12">12</option>
<option value="choix13">13</option>
<option value="choix14">14</option>
<option value="choix15">15</option>
<option value="choix16">16</option>
<option value="choix17">17</option>
<option value="choix18">18</option>
<option value="choix19">19</option>
<option value="choix20">20</option>
<option value="choix21">21</option>
<option value="choix22">22</option>
<option value="choix23">23</option>
<option value="choix24">24</option>
<option value="choix25">25</option>
<option value="choix26">26</option>
<option value="choix27">27</option>
<option value="choix28">28</option>
<option value="choix29">29</option>
<option value="choix30">30</option>
<option value="choix31">31</option>
</select>
<select name="Mois">
<option value="Mois1">Janvier</option>
<option value="Mois2">Février</option>
<option value="Mois3">Mars</option>
<option value="Mois4">Avril</option>
<option value="Mois5">Mai</option>
<option value="Mois6">Juin</option>
<option value="Mois7">Juillet</option>
<option value="Mois8">Aout</option>
<option value="Mois9">Septembre</option>
<option value="Mois10">Octobre</option>
<option value="Mois11">Novembre</option>
<option value="Mois12">Décembre</option>
</select>
<select name="select">
<option value="An">1900</option>
<option value="An1">1901</option>
</select>
<br />
(Jour / Mois / Année)</td>
</tr>
</table>
<table width="421" height="30" border="0">
<tr>
<td width="177">Lieu de Naissance : </td>
<td width="224"><input type="text" name="nom3" size="38" /></td>
</tr>
</table>
<table width="421" height="62" border="0">
<tr>
<td width="177">Profession :</td>
<td width="224"><input type="text" name="professio," size="38" /></td>
</tr>
<tr>
<td>Addresse : </td>
<td><input type="text" name="addresse_ele" size="38" /></td>
</tr>
<tr>
<td>Carte d'identité N° : </td>
<td><input type="text" name="num_ci_ele" size="38" /></td>
</tr>
</table>
</fieldset></td>
</tr>
<tr>
<td width="424" height="265"><fieldset>
<legend><strong>Empreinte digitale</strong></legend>
<table width="421" height="208" border="0">
<tr>
<td width="201" height="202"><fieldset>
<table width="200" border="0">
<tr>
<td height="190"> </td>
</tr>
</table>
</fieldset></td>
<td width="204"><center>
<input type="submit" name="Submit" value="Capturer l'empreinte" id="Submit" />
</center></td>
</tr>
</table>
<table width="420" border="0">
<tr>
<td width="410"><center >
<input type="submit" name="Submit" value="Enregistrer les informations" id="Submit" />
</center></td>
</tr>
</table>
</fieldset></td>
</tr>
</form>
</table>
</div>
<div id="affi">
<center> <h4>Affichage des électeurs déjà enregistrés</h4>
<hr />
<table width= "400" border="1">
<tr>
<td width="50"><strong>Numéro</strong></td>
<td width="120"><strong>Nom</strong></td>
<td width="160"><strong>Prénoms</strong></td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_Recordset1['id_ele']; ?></td>
<td><?php echo $row_Recordset1['nom_ele']; ?></td>
<td><?php echo $row_Recordset1['pre_ele']; ?></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
<p> </p>
</center>
</div>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
AIDEZ MOI SIL VOUS PLAIT
A voir également:
- Probleme denregistrement dans ma base mysql
- Base de registre - Guide
- Formules mathématiques de base - Télécharger - Études & Formations
- Mysql community download - Télécharger - Bases de données
- Formules excel de base - Guide
- Gigaset as470h base ✓ - Forum telephonie fixe
5 réponses
Déjà, si ton champ id_ele est une clef primaire en auto-increment tu peux écrire :
Ensuite pour savoir si ta requete s'execute ou pas:
// Ensuite on enregistre l'électeur
mysql_query("INSERT INTO electeur(id_ele,nom_ele,pre_ele,) VALUES(NULL, '$nom', '$prenom')");
Ensuite pour savoir si ta requete s'execute ou pas:
// Ensuite on enregistre l'électeur
if (mysql_query("INSERT INTO electeur(id_ele,nom_ele,pre_ele,) VALUES(NULL, '$nom', '$prenom')")){ echo 'requete execute';}else{echo 'rate';}
J'ai pris le temps de relire ton code entièrement et ça ne risque pas de marcher...
Tu lui dis SI :
Faire :
Or la moitié des champs que tu vérifie n'existe pas dans ton formulaire...
Certains ont des nom bizarres comme <input type="text" name="professio," size="38" />
D'autres n'existent même pas comme $_POST['sexe_ele'].
Bref si tu lui dis si $_POST['sexe_ele'] existe fais ça et que $_POST['sexe_ele']. n'existe pas, il ne le fera pas.
Je crois qu'il faut que tu reprennes ton code dans sa totalité.
Tu lui dis SI :
if (isset($_POST['nom_ele']) AND isset($_POST['pre_ele']) AND isset($_POST['sexe_ele']) AND isset($_POST['lieu_nais_ele']) AND isset($_POST['profession']) AND isset($_POST['date_nais_ele']) AND isset($_POST['addresse_ele']) AND isset($_POST['num_ci_ele']) AND isset($_POST['tel_ele'])) // Si les variables existent
{
Faire :
// Ensuite on enregistre l'électeur
mysql_query("INSERT INTO electeur(id_ele,nom_ele,pre_ele,) VALUES('', '$nom', '$prenom')");
Or la moitié des champs que tu vérifie n'existe pas dans ton formulaire...
Certains ont des nom bizarres comme <input type="text" name="professio," size="38" />
D'autres n'existent même pas comme $_POST['sexe_ele'].
Bref si tu lui dis si $_POST['sexe_ele'] existe fais ça et que $_POST['sexe_ele']. n'existe pas, il ne le fera pas.
Je crois qu'il faut que tu reprennes ton code dans sa totalité.
Ok merci beaucoup j'ai repris mon code et cela marche
J'ai un autre probleme
Comment lier les table de ma BD mysql comme on le fait dans MS access?
J'ai un autre probleme
Comment lier les table de ma BD mysql comme on le fait dans MS access?
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question