Bonjour,

J'ai un formulaire assez simple gérant des enregistrements dans une table 'sondages'.
Je n'arrive pas à m'en sortir car à chaque 'insert' j'en récupère 2 !!!!

j'ai donc besoin d'aide.

Voici la structure de ma table :
Code SQL : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
-- Adminer 4.8.0 MySQL 5.7.31 dump
 
SET NAMES utf8;
SET time_zone = '+00:00';
SET foreign_key_checks = 0;
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
 
DROP TABLE IF EXISTS `sondages`;
CREATE TABLE `sondages` (
  `id_sondage` int(6) NOT NULL AUTO_INCREMENT,
  `id_initiateur` int(11) DEFAULT NULL,
  `nom_sondage` varchar(64) NOT NULL,
  `nbre_questions` int(3) NOT NULL,
  `cible_sondage` varchar(64) NOT NULL,
  `date_creation` date NOT NULL,
  `date_cloture` date NOT NULL,
  PRIMARY KEY (`id_sondage`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
 
-- 2021-06-12 16:36:37

et voici le code de mon formulaire :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php session_start(); 
 
	//  Ges_Sondage... inspiré de Ges_Pelerinages et de SStatuts pour le sans_destroy  05/06/2021
	//  (et aussi de Ges_Agenda pour le sans_destroy)
 
	include_once ("En_tete_HV.php");
 
	$id_personne_log = $_SESSION['id_personne_log'];  echo "id_personne_log : ".$id_personne_log; echo "<br>"; echo "<br>"; echo "<br>"; 
 
	$code_site 	= $_SESSION['code_site'];  										//		   echo "code_site : ".$code_site;  echo"<br>";
	$nom_site 	= $_SESSION['nom_site'];  
	$domaine 	= $_SERVER['SERVER_NAME'];	
	$today 		= date("d/m/Y");        //   d à H:i:s"); 
 
	echo '<div class="no_print" >';      				//  Pas d'impression	
 
	echo " <input type=button class='btn' style='font-size:100%;  color:black;' onclick=window.location.href='Ges_Tables_Parametres_HV.php'; value='Retour au Menu des PARAMETRES' />"; echo "<br>";
	echo "<br>";
	echo '</div>';										//  On imprimera
 
	echo " <h1> Gestion des SONDAGES </h1> ";  //  au : ".$today."</h1> "; 
 
 
	//*********************************************************************************
	//  Liste de TOUS les SONDAGES  ***************************************************
	//*********************************************************************************
 
	?>
    <table>
	<tr align='center'>
		<!--	<th> N°    	</th>  -->
		<th> id_sondage   	</th> 
		<th> Initiateur       	</th> 
		<th> NOM_du_Sondage       	</th> 
		<th> Cible_sondage    </th> 
		<th> Nb_quest   	</th> 
		<th> Date_Création    </th> 
		<th> Date_Clôture    </th> 
	<!--	<th> Actions 		</th> -->
	</tr> 
	<?php
 
	$num = 0;
	$my_sql = "SELECT * FROM sondages ORDER BY id_sondage ASC ";
	$result = mysqli_query($my_cnx, $my_sql) or die ('Erreur ici vers 133 : '.mysqli_error($my_cnx) );
	$nb_sondages = mysqli_num_rows($result);
	while ($ligne = mysqli_fetch_assoc($result)) {
		$num ++;
		echo "<tr>";
		//	echo "<td>"."&nbsp &nbsp".$num.					"</td>";  
			echo "<td>"."&nbsp &nbsp".$ligne['id_sondage'].		"</td>";
			echo "<td>"."&nbsp &nbsp".$ligne['id_initiateur'].	"</td>";
			echo "<td>"."&nbsp &nbsp".$ligne['nom_sondage'].	"</td>";
			echo "<td>"."&nbsp &nbsp".$ligne['cible_sondage'].	"</td>";
			echo "<td>"."&nbsp &nbsp".$ligne['nbre_questions'].	"</td>";
			echo "<td>"."&nbsp &nbsp".$ligne['date_creation'].	"</td>";
			echo "<td>"."&nbsp &nbsp".$ligne['date_cloture'].	"</td>";
 
			// echo "<td>";
			// echo "<input type=button class='btn' style='font-size:100%; color:black;'  onclick=window.location.href='Ges_Sondages_HV.php?voir_detail=$ligne[id_sondage]'; value='Détails'/>  ";
			// echo "<input type=button class='btn' style='font-size:100%; color:black;'  onclick=window.location.href='Ges_Sondages_HV.php?modif_sondage=$ligne[id_sondage]'; value='Modifier'/>  ";
			// echo "<input type=button class='btn' style='font-size:100%; color:black;'  onclick=window.location.href='Ges_Sondages_HV.php?suppr_sondage=$ligne[id_sondage]'; value='Supprimer'/>  </center> ";
			// echo "</td>";  
		echo "</tr>";
	}	
	echo "</table>";
	echo " <h3> Il y a ".$nb_sondages." Sondages. </h3> "; echo "<br>"; 
	echo " <form name='form1'  method='post'  action='Ges_Sondages_HV.php' > ";
 
	//echo " <input type='submit' name='button' class='btn' style='font-size:100%; color:black;'  size='40' value='ABANDON' > ";
	echo " &nbsp &nbsp &nbsp &nbsp";
	echo " <input type='submit' name='button' class='btn' style='font-size:100%; color:black;'  size='40' value='Créer un NOUVEAU Sondage' > ";
	echo " &nbsp &nbsp &nbsp &nbsp";
	echo ' <input class="btn" id="impression" name="impression" type="button" style="font-size:100%; color:black;"  onclick="imprimer_page()" value="Imprimer CETTE liste " /> '." &nbsp &nbsp"; 
 
 
 
 
 
 
 
	if(isset($_POST['button'])) { 
 
		echo "<br>"; echo "<br>"; echo"valeur du POST-button : ".$_POST['button'];
 
		switch ($_POST['button']) { 
 
			case "Créer un NOUVEAU Sondage" : 
				echo " <form name='form1'  method='post'  action='Ges_Sondages_HV.php' > ";
				echo "<br>"; echo "<br>"; echo "<br>";echo "<br>"; echo "<br>"; 
				echo " CREATION d'un NOUVEAU SONDAGE"; echo "<br>"; echo "<br>"; 
 
				?>	
				<table> 
					<tr align='center'>    <th> NOM du Sondage </th>	<th> nbre_questions </th>   <th> Cible_Sondage </th> <th> date_creation </th>    <th> Date_Clôture </th>                                                  </tr>  	
					<tr> 
						<td> <input  name="nom_sondage" 	autofocus required	size="30"    type="text"     > </td>	
						<td> <input  name="nbre_questions" 		size="10"    type="number"     > </td>
						<td> <input  name="cible_sondage" 		size="30"    type="text"     > </td>	
						<td> <input  name="date_creation" 		size="10"    type="date"     > </td>	
						<td> <input  name="date_cloture" 		size="10"    type="date"     > </td>	
					</tr>
	  			</table>
				<?php
 
				echo "<br>"; 
				echo " <input type=button class='btn' style='font-size:100%; color:black;' onclick=window.location.href='Ges_Sondages_HV.php';  value='ABANDON' > ";
				echo " &nbsp &nbsp &nbsp &nbsp";
				echo " <input type='submit' name='button' class='btn' style='font-size:100%; color:black;'  size='40' value='VALIDER ce NOUVEAU Sondage' > ";
				echo "<br>"; echo "<br>"; echo "<br>";
				echo "</form>";
				exit;
			break;
 
 
 
 
 
			case "VALIDER ce NOUVEAU Sondage" :
				echo "<br>"; echo "<br>"; 
				$nom_sondage 	= $_POST['nom_sondage']; $nom_sondage = isset($nom_sondage)? addslashes($nom_sondage) : '';	         // gestion des apostrophes dans le cas des 'Sables d'Olonne' 04_05_2021
				$nbre_questions = $_POST['nbre_questions'];
				$cible_sondage	= $_POST['cible_sondage'];
				$date_creation	= $_POST['date_creation'];
				$date_cloture	= $_POST['date_cloture'];
 
				$id_initiateur = $id_personne_log;
 
				$my_sql = "INSERT INTO sondages (id_initiateur, nom_sondage, nbre_questions, cible_sondage, date_creation, date_cloture) VALUES ( '{$id_initiateur}', '{$nom_sondage}', '{$nbre_questions}', '{$cible_sondage}', '{$date_creation}', '{$date_cloture}' )";
				$result = mysqli_query($my_cnx,$my_sql) or die ("Erreur en 387 : ".mysqli_error($my_cnx));
 
				echo "<br>"; echo "<br>"; echo "texte de la requete d'insertion en base : ".$my_sql; //  exit;
 
	 	  		if (mysqli_query($my_cnx, $my_sql)) {  	
					$message= "Création REALISEE avec SUCCES"; echo"<br>"; 
					echo "<font color='green'> ".$message; echo"<br>"; 
				}else{
					$message = "ERREUR dans la REQUETE vers 118 : "."<br>" .$my_sql . "<br><br>" .mysqli_error($my_cnx)."<br>"; 
		   	  		echo $message; //exit;
				}
				echo "<br>"; echo "<br>"; echo "OK après insertion du NOUVEL enregistrement "; 
				echo "<script type='text/javascript'>document.location.replace('Ges_Sondages_HV.php');</script>";     //  Redirection immédiate ....   ça marche chez 1&1
				exit;
			break;
 
 
 
			case "ABANDON" :	//  Cet ABANDON va vers le Retour au Menu des Tables des Paramètres
				echo "<script type='text/javascript'>document.location.replace('Ges_Tables_Parametres_HV.php');</script>";     //  Redirection immédiate ....   ça marche chez 1&1
				//echo " <input class='btn'  type=button style='font-size:150%; color:black;' onclick=window.location.href='Ges_Tables_Parametres_HV.php'; value='ABANDON' />"; echo "<br>";
				exit;
			break;
 
 
 
			default:
				echo "<br>";   
				echo "<br>"; 
				echo " <h2> Aucun choix 'TROUVE' dans le Select 'Switch' (Vérifier l'orthographe des 'case' ) !!! </h2> "; 
				echo "<br>"; echo "<br>";
				exit;		
			break;
 
		}	//  Fin du switch	
 
	}		//  Fin du  if(isset($_POST['button'])) { 
 
 
 
 
	?>
	<script type="text/javascript">
		function imprimer_page(){window.print();}
	</script>

Merci d'avance

Cordialement
Maub