S affiche: " Undefined index: agent_nbre"

<table>
<tr>
<form action=<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?> method="POST">
<td>Nombre d'agent en mission :</td>
<td><input type="text" name="agent_nbre"></td></form>
</tr>
<?php

$agent_num=$_POST['agent_nbre'];
for($i=0;$i<$agent_num;$i++)
{
?>

1 réponse

  • Votes
  • Date
  • Date décroissante
  1. Modérateur
    Bonjour

    Verifie que ta variable existe via ISSET.
    par exemple:
    $agent_num = isset($_POST['agent_nbre']) ? $_POST['agent_nbre'] : 0 ;
    


    Cordialement, 
    Jordane                                                                 
    1. en fait le code fonctionne sauf que c message s’affiche " Notice: Undefined index: agent_nbre in C:\Users\Navid\Desktop\EasyPHP-5.3.8.0\www\Monprojet\mission.php on line 76 " je même initialiser la variable ("agent_nbre"
      )
    2. @jordane45
      <code><table> 
      <tr>
                  <form action=<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?> method="POST">
                  <td>Nombre d'agent en mission :</td>
                  <td><input type="text" name="agent_nbre"></td></form>
              </tr>
      <?php 
       ;
      $agent_num=$_POST['agent_nbre'];
      for($i=0;$i<$agent_num;$i++) 
      {
      ?>
      
      
      
      <form action="enregistrement.php"  methode="post">
                <tr>
                  <?php 
          $base=mysql_connect('localhost','root', '' );
          mysql_select_db('mamission',$base);
          
          $sql = 'SELECT Num_Mission FROM mission order by Num_Mission Asc'; 
          $req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
          
          
          while($data = mysql_fetch_array($req))
          {
              $num= $data['Num_Mission'];
              } 
          
            mysql_close();
          ?>
              <td width="169" height="28">Numero de mission : </td>
              <td width="371"><input type="text" name="numero" size="30" value="<?php echo $num=$num+1; ?>" > </td>
            <?php 
            
            ?>
      
            </tr>
      
      
                <tr>
              <td heigt=29>Matricule d'agent : </td>
          
              <?php 
          $base=mysql_connect('localhost','root', '' );
          mysql_select_db('mamission',$base);
          
          $sql = 'SELECT Matricule_Agent FROM agent'; 
          $req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
          
          ?>
              <td> <select name="Matricule_Agent" >
          <?php
          while($data = mysql_fetch_array($req))
          {
          ?>
          <option value="<?php echo $data['Matricule_Agent']?>"><?php echo $data['Matricule_Agent']?></option>
          <?php
          } 
          mysql_close(); 
          ?>
          </select></td>
            <tr>
              <td height="29">Nom d'agent : </td>
          <?php 
          $base=mysql_connect('localhost','root', '' );
          mysql_select_db('mamission',$base);
          
          $sql = 'SELECT Nom_Agent FROM agent'; 
          $req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
          
          ?>
              <td> <select name="agent" >
          <?php
          while($data = mysql_fetch_array($req))
          {
          ?>
          <option value="<?php echo $data['Nom_Agent']?>"><?php echo $data['Nom_Agent']?></option>
          <?php
          } 
          mysql_close(); 
          ?>
          </select>
          
          </td>
            </tr>
            
            </tr>
             <tr>
              <td height=29>Service d'agent: </td>
              <?php 
          $base=mysql_connect('localhost','root', '' );
          mysql_select_db('mamission',$base);
          
          $sql = 'SELECT Service FROM vehicule'; 
          $req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
          
          ?>
              <td> <select name="service">
          <?php
          while($data = mysql_fetch_array($req))
          {
          ?>
          <option value="<?php echo $data['Service']?>"><?php echo $data['Service']?></option>
          <?php
          } 
          mysql_close(); 
          ?>
          </select></td>
            </tr>
             <tr>
              <td width="169" height="28">Télephone d'Agent : </td>
              <td width="371"><input type="text" name="Tel" size="30" class="formilaire"> </td>
      
            </tr>
            <tr>
              <td>______________________</td>
            </tr>
      <?php
      
      }
      ?>
          </table>
      </code>
    3. en fait lorsque je donne un nombre donner d'agent , sa doit mes donner automatiquement le même formulaire pour chacun !!!