Probleme d'insertion multiple

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : Probleme d'insertion multiple

par jpaul » 04 avr. 2006, 22:29

Hum !
Le problème ne viendrait-il pas du fait que les select du formulaires n'ont pas de champ name ?
Je ne suis pas sûr mais je trouve ça louche !
En tous cas il n'y a rien pour initialiser num_semaine donc le test avec $_POST['num_semaine'] sera toujours négatif....

par universdupc » 04 avr. 2006, 09:11

seriez-vous d'ou ca vient car la je pense avoir bien tout fait :
<?php
$mysqlhost = "localhost";
$name = "root";
$password = "";
$bdd = "pointage";

if (isset($_POST['go']) && $_POST['go']=='Ajouter') {
    
    //if ((isset($_POST['jours'])) && (isset($_POST['num_semaine']))) {
        // si les 4 variables ne sont pas vides, et si l'adresse E-mail est valide, alors, et seulement dans ce cas, on fera notre insertion dans la base
        //if ((!empty($_POST['jours'])) && (!empty($_POST['num_semaine']))) {
            // on verifie le format de l'adresse E-mail saisie
           // $test_mail = eregi ('^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)+$', $_POST['agenda_email']);
            //if ($test_mail) {
                // on se connecte à notre base 
                $base = mysql_connect ($mysqlhost,$name,$password);  
                mysql_select_db ($bdd,$base);  

                // on prepare notre requête d'insertion des données
                $sql = 'INSERT INTO saisie VALUES("", "'.addslashes($_POST['num_semaine']).'", "'.addslashes($_POST['jours']).'", "'.addslashes($_POST['heur_arriv']).'", "'.addslashes($_POST['heur_dep']).'", "'.addslashes($_POST['heur_heur_dep_pau']).'", "'.addslashes($_POST['heur_ret_pau']).'", "","'.addslashes($_POST['date']).'", "'.addslashes($_POST['mois']).'", "'.addslashes($_POST['annees']).'")';

                // on lance la requête
                mysql_query($sql) or die('Erreur SQL !'.$sql.'<br />'.mysql_error());

                // on ferme la connection à la base de données
                mysql_close();

                // on redirige le visiteur vers l'accueil du livre d'or
                //header('location: index.php');
		     echo"enregistrement réussit cliquez <a href='index.php'>ici</a> pour revenir à la page des favorie.";
                // on termine le scrit courant
                exit();
            //}
            //else {
              //  $erreur = 'Votre adresse E-mail est invalide.';
		
	      //}
        //}
       // else {
        //    $erreur = 'Au moins un des champs est vide.';
        //}
    //}
    //else {
      //  $erreur = 'Les variables nécessaires au script ne sont pas définies.';
   // }
}
?>
<html> 
<head> 
<title>Insérer une nouvelle feuille de pointage</title> 
<SCRIPT language="JavaScript" type="text/javascript">
  <!--
    //Saisie d'un memo
    function saisieOK(theForm) {
	if (theForm.jours.value == "") {
        window.alert("Veuillez entrer le jours");
        theForm.jours.focus();
        return (false);
      }
      if (theForm.heur_arriv.value == "") {
        window.alert("Veuillez entrer la description pour la catégorie");
        theForm.heur_arriv.focus();
        return (false);
      }
if (theForm.heur_ret.value == "") {
        window.alert("Veuillez entrer la description pour la catégorie");
        theForm.heur_ret.focus();
        return (false);
      }
if (theForm.heur_dep_pau.value == "") {
        window.alert("Veuillez entrer la description pour la catégorie");
        theForm.heur_dep_pau.focus();
        return (false);
      }
if (theForm.heur_ret_pau.value == "") {
        window.alert("Veuillez entrer la description pour la catégorie");
        theForm.heur_ret_pau.focus();
        return (false);
      }

	theForm.submit();
      return (true);
    }
  //-->
  </SCRIPT>
</head> 
<body> 
<center>
<h2>Enregistrer une nouvelle feuille de pointage</h2>
</center> 
<br> 
<br>
<center>
<form action="insert.php" method="post" name="ajout">
<table>
<hr>
<tr><td>
<span class="gras">Numero de semaine :</span>
</td><td>
<select value="<?php if (isset($_POST['num_semaine'])) echo stripslashes(htmlentities(trim($_POST['num_semaine']))); ?>">
<?php 
$int=50;
for($i=1; $i != $int ; $i++) 
{
echo"<option>";
echo"$i<br>"; 
echo"</option>";
} 
?>
</select>
</td></tr>
<tr><td>
<span class="gras">Jours :</span>
</td><td>
<select value="<?php if (isset($_POST['date'])) echo stripslashes(htmlentities(trim($_POST['date']))); ?>">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
</select>
</td></tr>
<tr><td>
<span class="gras">Mois :</span>
</td><td>
<select value="<?php if (isset($_POST['mois'])) echo stripslashes(htmlentities(trim($_POST['mois']))); ?>">
<option>Janvier</option>
<option>Frévrier</option>
<option>Mars</option>
<option>Avril</option>
<option>Mais</option>
<option>Juin</option>
<option>Juillet</option>
<option>Août</option>
<option>Septembre</option>
<option>Octobre</option>
<option>novembre</option>
<option>Decembre</option>
</select>
</td></tr>
<tr><td>
<span class="gras">Années :</span>
</td><td>
<select value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>">
<?php 
$int=3001;
for($i=2005; $i != $int ; $i++) 
{
echo"<option>";
echo"$i<br>"; 
echo"</option>";
} 
?>
</select>
</td></tr>
<table border="1">
<tr>
 <td>
  Jours
 </td>
 <td>
  heure d'arrivé
 </td>
 <td>
  heure de départ
 </td>
 <td>
  heure départ pause
 </td>
 <td>
  heure retour pause
 </td>
</tr>
<tr>
<td>
<input type="text" name="jours" maxlength="50" size="10" value="<?php if (isset($_POST['jours'])) echo stripslashes(htmlentities(trim($_POST['jours']))); ?>">
</td>
<td>
<input type="text" name="jours" maxlength="50" size="10" value="<?php if (isset($_POST['heur_arriv'])) echo stripslashes(htmlentities(trim($_POST['heur_arriv']))); ?>">
</td>
<td>
<input type="text" name="heur_arriv" maxlength="50" size="10" value="<?php if (isset($_POST['heur_dep'])) echo stripslashes(htmlentities(trim($_POST['heur_dep']))); ?>">
</td>
<td>
<input type="text" name="heur_dep" maxlength="50" size="10" value="<?php if (isset($_POST['heur_dep_pau'])) echo stripslashes(htmlentities(trim($_POST['heur_dep_pau']))); ?>">
</td>
<td>
<input type="text" name="heur_dep_pau" maxlength="50" size="10" value="<?php if (isset($_POST['heur_ret_pau'])) echo stripslashes(htmlentities(trim($_POST['heur_ret_pau']))); ?>">
</td>
</tr>
</table>
<tr><td colspan="2">
</td></tr>
<tr><td>
<input type="submit" name="go" value="Ajouter" onClick="javascript: return saisieOK(document.ajout);"> 
</td>
</form>
<td align="right"><form method=get action='index.php'><input type=submit value='Annuler'></td></form>
</tr></table>
</center>

</body>
</html>

par universdupc » 04 avr. 2006, 08:50

ok Mais est-il possible d'insérer plusieurs tuples dans une base de données en même temps.

Je m'explique j'ai uine base données "saisie" dedant se trouve plusieurs champ (id, moi, jour, date...) et j'aimerais créer un tableau ou l'on insèreplusieur valeur de lundi à dimanche. Chauqe jours correspond à un tuple en faite. ET donc est il possible de les insérer tous en même temps dans la base.

par jpaul » 03 avr. 2006, 17:49

Salut,

Après un rapide coup d'oeil, tu as un test :
    if ((isset($_POST['jours'])) && (isset($_POST['num_semaine']))) {
J'ai bien vu une initialisation pour jours mais pas pour num_semaine !!!

Probleme d'insertion multiple

par universdupc » 03 avr. 2006, 17:41

bonjour !

Salut !

Voilà j'ai fait un code pour insérer plusieurs valeurs dans une table de données. Mais quand je valaide rien ne se passe seriez-vous pourquoi ?
C'est en faite un tableau que je remplie pour lundi jusque dimanche, et je veux que tous les champs viennent ce mettre dans la base de données les une à la suite des autre.

Voici le code :
<?php 
$mysqlhost = "localhost"; 
$name = "root"; 
$password = ""; 
$bdd = "pointage"; 

if (isset($_POST['go']) && $_POST['go']=='Ajouter') { 
     
    if ((isset($_POST['jours'])) && (isset($_POST['num_semaine']))) { 
        // si les 4 variables ne sont pas vides, et si l'adresse E-mail est valide, alors, et seulement dans ce cas, on fera notre insertion dans la base 
        if ((!empty($_POST['jours'])) && (!empty($_POST['num_semaine']))) { 
            // on verifie le format de l'adresse E-mail saisie 
           // $test_mail = eregi ('^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)+$', $_POST['agenda_email']); 
            //if ($test_mail) { 
                // on se connecte à notre base  
                $base = mysql_connect ($mysqlhost,$name,$password);   
                mysql_select_db ($bdd,$base);   

                // on prepare notre requête d'insertion des données 
                $sql = 'INSERT INTO saisie VALUES("", "'.addslashes($_POST['num_semaine']).'", "'.addslashes($_POST['jours']).'", "'.addslashes($_POST['heur_arriv']).'", "'.addslashes($_POST['heur_dep']).'", "'.addslashes($_POST['heur_heur_dep_pau']).'", "'.addslashes($_POST['heur_ret_pau']).'", "","'.addslashes($_POST['date']).'", "'.addslashes($_POST['mois']).'", "'.addslashes($_POST['annees']).'")'; 

                // on lance la requête 
                mysql_query($sql) or die('Erreur SQL !'.$sql.'<br />'.mysql_error()); 

                // on ferme la connection à la base de données 
                mysql_close(); 

                // on redirige le visiteur vers l'accueil du livre d'or 
                //header('location: index.php'); 
             echo"enregistrement réussit cliquez <a href='index.php'>ici</a> pour revenir à la page des favorie."; 
                // on termine le scrit courant 
                exit(); 
            //} 
            //else { 
              //  $erreur = 'Votre adresse E-mail est invalide.'; 
         
          //} 
        } 
        else { 
            $erreur = 'Au moins un des champs est vide.'; 
        } 
    } 
    else { 
        $erreur = 'Les variables nécessaires au script ne sont pas définies.'; 
    } 
} 
?> 
<html>  
<head>  
<title>Insérer une nouvelle feuille de pointage</title>  
<SCRIPT language="JavaScript" type="text/javascript"> 
  <!-- 
    //Saisie d'un memo 
    function saisieOK(theForm) { 
    if (theForm.annees.value == "") { 
        window.alert("Veuillez entrer le nom d'une catégorie"); 
        theForm.categorie_nom.focus(); 
        return (false); 
      } 
      if (theForm.heur_arriv.value == "") { 
        window.alert("Veuillez entrer la description pour la catégorie"); 
        theForm.categorie_description.focus(); 
        return (false); 
      } 
    theForm.submit(); 
      return (true); 
    } 
  //--> 
  </SCRIPT> 
</head>  
<body>  
<center> 
<h2>Enregistrer une nouvelle feuille de pointage</h2> 
</center>  
<br>  
<br> 
<center> 
<form action="insert.php" method="post" name="ajout"> 
<table> 
<hr> 
<tr><td> 
<span class="gras">Numero de semaine :</span> 
</td><td> 
<select value="<?php if (isset($_POST['num_semaine'])) echo stripslashes(htmlentities(trim($_POST['num_semaine']))); ?>"> 
<?php  
$int=8; 
for($i=1; $i != $int ; $i++)  
{ 
echo"<option>"; 
echo"$i<br>";  
echo"</option>"; 
}  
?> 
</select> 
</td></tr> 
<tr><td> 
<span class="gras">Jours :</span> 
</td><td> 
<select value="<?php if (isset($_POST['date'])) echo stripslashes(htmlentities(trim($_POST['date']))); ?>"> 
<option>1</option> 
<option>2</option> 
<option>3</option> 
<option>4</option> 
<option>5</option> 
<option>6</option> 
<option>7</option> 
<option>8</option> 
<option>9</option> 
<option>10</option> 
<option>11</option> 
<option>12</option> 
<option>13</option> 
<option>14</option> 
<option>15</option> 
<option>16</option> 
<option>17</option> 
<option>18</option> 
<option>19</option> 
<option>20</option> 
<option>21</option> 
<option>22</option> 
<option>23</option> 
<option>24</option> 
<option>25</option> 
<option>26</option> 
<option>27</option> 
<option>28</option> 
<option>29</option> 
<option>30</option> 
<option>31</option> 
</select> 
</td></tr> 
<tr><td> 
<span class="gras">Mois :</span> 
</td><td> 
<select value="<?php if (isset($_POST['mois'])) echo stripslashes(htmlentities(trim($_POST['mois']))); ?>"> 
<option>Janvier</option> 
<option>Frévrier</option> 
<option>Mars</option> 
<option>Avril</option> 
<option>Mais</option> 
<option>Juin</option> 
<option>Juillet</option> 
<option>Août</option> 
<option>Septembre</option> 
<option>Octobre</option> 
<option>novembre</option> 
<option>Decembre</option> 
</select> 
</td></tr> 
<tr><td> 
<span class="gras">Années :</span> 
</td><td> 
<select value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>"> 
<?php  
$int=3001; 
for($i=2005; $i != $int ; $i++)  
{ 
echo"<option>"; 
echo"$i<br>";  
echo"</option>"; 
}  
?> 
</select> 
</td></tr> 
<table border="1"> 
<tr> 
 <td> 
  Jours 
 </td> 
 <td> 
  heure d'arrivé 
 </td> 
 <td> 
  heure de départ 
 </td> 
 <td> 
  heure départ pause 
 </td> 
 <td> 
  heure retour pause 
 </td> 
</tr> 
<tr> 
<td> 
<input type="text" name="jours" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>Lundi"> 
</td> 
<td> 
<input type="text" name="heur_arriv" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>"> 
</td> 
<td> 
<input type="text" name="heur_dep" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>"> 
</td> 
<td> 
<input type="text" name="heur_dep_pau" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>"> 
</td> 
<td> 
<input type="text" name="heur_ret_pau" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>"> 
</td> 
</tr> 
<tr> 
<td> 
<input type="text" name="jours" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>Mardi"> 
</td> 
<td> 
<input type="text" name="heur_arriv" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>"> 
</td> 
<td> 
<input type="text" name="heur_dep" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>"> 
</td> 
<td> 
<input type="text" name="heur_dep_pau" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>"> 
</td> 
<td> 
<input type="text" name="heur_ret_pau" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>"> 
</td> 
</tr> 
<tr> 
<td> 
<input type="text" name="jours" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>Mercredi"> 
</td> 
<td> 
<input type="text" name="heur_arriv" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>"> 
</td> 
<td> 
<input type="text" name="heur_dep" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>"> 
</td> 
<td> 
<input type="text" name="heur_dep_pau" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>"> 
</td> 
<td> 
<input type="text" name="heur_ret_pau" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>"> 
</td> 
</tr> 
<tr> 
<td> 
<input type="text" name="jours" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>Jeudi"> 
</td> 
<td> 
<input type="text" name="heur_arriv" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>"> 
</td> 
<td> 
<input type="text" name="heur_dep" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>"> 
</td> 
<td> 
<input type="text" name="heur_dep_pau" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>"> 
</td> 
<td> 
<input type="text" name="heur_ret_pau" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>"> 
</td> 
</tr> 
<tr> 
<td> 
<input type="text" name="jours" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>Vendredi"> 
</td> 
<td> 
<input type="text" name="heur_arriv" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>"> 
</td> 
<td> 
<input type="text" name="heur_dep" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>"> 
</td> 
<td> 
<input type="text" name="heur_dep_pau" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>"> 
</td> 
<td> 
<input type="text" name="heur_ret_pau" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>"> 
</td> 
</tr> 
<tr> 
<td> 
<input type="text" name="jours" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>Samedi"> 
</td> 
<td> 
<input type="text" name="heur_arriv" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>"> 
</td> 
<td> 
<input type="text" name="heur_dep" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>"> 
</td> 
<td> 
<input type="text" name="heur_dep_pau" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>"> 
</td> 
<td> 
<input type="text" name="heur_ret_pau" maxlength="50" size="10" value="<?php if (isset($_POST['annees'])) echo stripslashes(htmlentities(trim($_POST['annees']))); ?>"> 
</td> 
</tr> 
<tr> 
<td> 
<input type="text" name="jours" maxlength="50" size="10" value="<?php if (isset($_POST['jours'])) echo stripslashes(htmlentities(trim($_POST['jours']))); ?>Dimanche"> 
</td> 
<td> 
<input type="text" name="heur_arriv" maxlength="50" size="10" value="<?php if (isset($_POST['heur_arriv'])) echo stripslashes(htmlentities(trim($_POST['heur_arriv']))); ?>"> 
</td> 
<td> 
<input type="text" name="heur_dep" maxlength="50" size="10" value="<?php if (isset($_POST['heur_dep'])) echo stripslashes(htmlentities(trim($_POST['heur_dep']))); ?>"> 
</td> 
<td> 
<input type="text" name="heur_dep_pau" maxlength="50" size="10" value="<?php if (isset($_POST['heur_dep_pau'])) echo stripslashes(htmlentities(trim($_POST['heur_dep_pau']))); ?>"> 
</td> 
<td> 
<input type="text" name="heur_ret_pau" maxlength="50" size="10" value="<?php if (isset($_POST['heur_ret_pau'])) echo stripslashes(htmlentities(trim($_POST['heur_ret_pau']))); ?>"> 
</td> 
</tr> 

</table> 
<tr><td colspan="2"><hr> 
</td></tr> 
<tr><td> 
<input type="submit" name="go" value="Ajouter">  
</td> 
</form> 
<td align="right"><form method=get action='index.php'><input type=submit value='Annuler'></td></form> 
</tr></table> 
</center> 

</body> 
</html> 

Merci d'avance[/code]