S affiche: " Undefined index: agent_nbre"

Fermé
Dias@ Messages postés 4 Date d'inscription lundi 14 mars 2016 Statut Membre Dernière intervention 14 mars 2016 - Modifié par Dias@ le 14/03/2016 à 08:10
Dias@ Messages postés 4 Date d'inscription lundi 14 mars 2016 Statut Membre Dernière intervention 14 mars 2016 - 14 mars 2016 à 19:46
<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

jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 4 650
Modifié par jordane45 le 14/03/2016 à 08:39
Bonjour

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


Cordialement, 
Jordane                                                                 
0
Dias@ Messages postés 4 Date d'inscription lundi 14 mars 2016 Statut Membre Dernière intervention 14 mars 2016
Modifié par Dias@ le 14/03/2016 à 12:59
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"
)
0
jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 4 650 > Dias@ Messages postés 4 Date d'inscription lundi 14 mars 2016 Statut Membre Dernière intervention 14 mars 2016
14 mars 2016 à 14:08
Montres nous ton code COMPLET .

PS : **** Attention ****
Merci de bien vouloir utiliser la coloration syntaxique (les balises de code) lorsque tu postes du code sur le forum.
Explications disponibles ici :
https://codes-sources.commentcamarche.net/faq/10686-le-nouveau-codes-sources-comment-ca-marche#balises-code

.
0
Dias@ Messages postés 4 Date d'inscription lundi 14 mars 2016 Statut Membre Dernière intervention 14 mars 2016 > jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024
Modifié par Dias@ le 14/03/2016 à 19:41
<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>
0
Dias@ Messages postés 4 Date d'inscription lundi 14 mars 2016 Statut Membre Dernière intervention 14 mars 2016
14 mars 2016 à 19:46
en fait lorsque je donne un nombre donner d'agent , sa doit mes donner automatiquement le même formulaire pour chacun !!!
0