PB d'utilisation de la boucle for

msi79
Nouveau WRInaute
Nouveau WRInaute
 
Messages: 2
Inscription: 5 Fév 2012

PB d'utilisation de la boucle for

Message le Dim Fév 05, 2012 14:37

salut . je suis entreint de créer un formulaire pour enregistrer des préjudices subis par des victimes de guerre .
le problème est que une victime peut avoir subis 0 ou plusieurs préjudices . mon formulaire dois donner la possibilité d'enregistrer 1 ou plusieurs préjudices.
voici mon code :
Code: Tout sélectionner
<?php
  if(isset($_GET['prejud_sid'])) $prejud_sid = urldecode($_GET['prejud_sid']);
if(isset($_POST['bouton_submit'])&& !empty($_POST['nbre'])){
$cat = strip_tags(trim($_POST['cat']));
 
    for($i = 1; $i <= $_POST['nbre']; $i++){
//if(isset($_FILES['img'.$i]) && $_FILES['img'.$i]['error'] == 0 && isset($_POST['nbre'])){
/*IMPORTANT*/

//include("connection.php");
// Connexion à la BDD
mysql_connect("localhost","root","") or die("erreur de connexion");
// Sélection de la base de données
mysql_select_db("DirectVictime2") or die("Erreur de selection de la BD");

/*faut securiser*/
foreach($_POST as $k => $v){
$v=mysql_real_escape_string(strip_tags($v));
$_POST[$k]=$v;
}

/*faut securiser*/
foreach($_GET as $k => $v){
$v=mysql_real_escape_string(strip_tags($v));
$_POST[$k]=$v;
}

   $NumCode='NumCode1'.$i;
   $NumCode1=trim($_POST["NumCode"]);
   
   
   $quantite='quantite1'.$i;
   $quantite1=trim($_POST["quantite"]);
   
   $dateSurv='dateSurv1'.$i;
   $dateSurv1=trim($_POST["dateSurv"]);
   
   $lieuSurv='lieuSurv1'.$i;
   $lieuSurv1=trim($_POST["lieuSurv"]);
   $designation='designation1'.$i;
   $designation1=trim($_POST["designation"]);
   
   $code='code1'.$i;
   $code1=trim($_POST["code"]);
   
   $naturePrej='naturePrej1'.$i;
   $naturePrej1=trim($_POST["naturePrej"]);
   
   $autrePrej='autrePrej1'.$i;
   $autrePrej1=trim($_POST["autrePrej"]);

if (empty($code1)) {
      $msg="<font color=red>Veuillez saisir  le numero du questionnaire!!!!!!!!!</font>";
   }
   else {
      

// on fait l'INSERT dans la base de données
      $sql="INSERT INTO prejudice1(id_prejudice1,NumCode1,designation1,code1,quantite1,dateSurv1,lieuSurv1,naturePrej1,autrePrej1,prejud_sid) VALUES('','".$NumCode1."','".$designation1."','".$code1."','".$quantite1."','".$dateSurv1."','".$lieuSurv1."','".$naturePrej1."','".$autrePrej1."','".$prejud_sid."')";
mysql_query($sql) or die(mysql_error());
echo 'Les informations sur les prejudices ont été ajoutées dans la base de données.</br>';

   }
}
      
}

//}

?>
<!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=iso-8859-1" />
<title>Document sans titre</title>
<style type="text/css">
<!--
.Style3 {
   color: #0000FF;
   font-weight: bold;
}
.Style4 {
   color: #990033;
   font-weight: bold;
}
.Style6 {color: #990000}
-->
</style>
</head>

<body>
<table width="200" border="0">
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
<table width="1179" height="38" border="0" align="left">
  <tr>
    <td width="107"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="107" height="18" title="IMAGES">
      <param name="movie" value="button9.swf" />
      <param name="quality" value="high" />
      <param name="bgcolor" value="#FFFFFF" />
      <embed src="button9.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="107" height="18" bgcolor="#FFFFFF"></embed>
    </object></td>
    <td width="355"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="107" height="18" title="VICTIMES">
      <param name="movie" value="button7.swf" />
      <param name="quality" value="high" />
      <embed src="button7.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="107" height="18" ></embed>
    </object></td>
    <td width="34">&nbsp;</td>
    <td width="34">&nbsp;</td>
    <td width="34">&nbsp;</td>
    <td width="34">&nbsp;</td>
    <td width="34">&nbsp;</td>
    <td width="34">&nbsp;</td>
    <td width="364">&nbsp;</td>
    <td width="107"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="107" height="18" title="PREJUDICES">
      <param name="movie" value="button11.swf" />
      <param name="quality" value="high" />
      <embed src="button11.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="107" height="18" ></embed>
    </object></td>
  </tr>
</table>
<h1 align="center" class="subfooter  Style3">Enregistrement de préjudices </h1>
<form action="" method="post" >
  <p>&nbsp;</p>
  <table width="570" height="95" border="0" align="center" bordercolor="#0000FF" bgcolor="#83E7FC">
  <tr> <td width="180"><span class="Style4">Saisir le nombre de préjudices:</span></td> <td width="380"><input name="nbre" type="text" size="1" maxlength="1" value="<?php if(isset($_POST['nbre']))echo $_POST['nbre'];?>"/></td> </tr> <tr> <td>&nbsp;</td> <td bordercolor="#0000FF"> <fieldset> <legend><span class="Style6">AJOUTER DES PREJUDICES</span></legend>   
  <?php if(isset($_POST['bouton_submit']) && ($_POST['nbre'])){ extract($_POST); $nbre_photo = $nbre; for($j = 1; $j<= $nbre_photo; $j++){ echo'
                    <table width="1203" border="0">
                      <tr>
                        <td width="54"><strong>
                          <input name="NumCode1" type="text" size="8" />
                        </strong></td>
                        <td width="149"><strong>
                          <input type="text" name="designation1" />
                        </strong></td>
                        <td width="94"><strong>
                          <input name="code1" type="text" size="15" />
                        </strong></td>
                        <td width="146"><strong>
                          <input type="text" name="quantite1" />
                        </strong></td>
                        <td width="147"><strong>
                          <input type="text" name="dateSurv1" />
                        </strong></td>
                        <td width="144"><strong>
                          <input type="text" name="lieuSurv1" />
                        </strong></td>
                        <td width="116"><strong>
                          <select name="naturePrej1">
                            <option></option>
                            <option>Pillage</option>
                            <option>Expropriation</option>
                            <option>R&eacute;quisition</option>
                            <option>Destruction</option>
                          </select>
                        </strong></td>
                        <td width="319">Autre<strong>
                          <input type="text" name="autrePrej1" />
                        </strong></td>
                      </tr>
                    </table><br/>'; } } ?> </fieldset> </td> </tr> <tr> <td>&nbsp;</td> <td><input type="submit" name="bouton_submit" value="envoyer" ></input></td> </tr></table>
</form>
<p>
  <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="50" height="37" title="ACCUEIL">
    <param name="movie" value="button4.swf" />
    <param name="quality" value="high" />
    <param name="bgcolor" value="#FFFFFF" />
    <embed src="button4.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="50" height="37" bgcolor="#FFFFFF"></embed>
  </object>
</p>
</body>
</html>

Si vous avez aimé cette discussion, partagez-la sur vos réseaux sociaux préférés :

Lectures recommandées sur ce thème :



Qui est en ligne

Utilisateurs parcourant ce forum: ISFR et 0 invités