Pb PHP

CSB -  
 kalamit -
salut,
j'essaie de faire un code pour modifier un fichier texte en ligne à l'aide d'un formulaire :
<HTML>
<BODY>
<?php
$ligne=$_POST["ligne"];
$fp = fopen ("essai.txt","a");
fputs ($fp,"$ligne");
fputs ($fp,"\n");
fclose ($fp);
?>
<FORM name="citation" action="citations.php" method="post">
Saisie : <INPUT NAME="ligne"><INPUT TYPE="submit">
</FORM>
</BODY>
</HTML>

il fonctionne sauf que quand je le lance j'ai l'erreur suivante :
Notice: Undefined index: ligne in e:\program files\easyphp1-7\www\csb\citations.php on line 5
que faire pour enrayer cette erreur ???
d'avance merci ;-)

1 réponse

  1. kalamit
     
    Salut,
    C'est normal.

    Je modifierais ton code comme suivant:
    <HTML> 
    <BODY> 
    <?php 
    if (isset($_POST['ligne']) {
       $ligne=$_POST['ligne']; 
       $fp = fopen ("essai.txt","a"); 
       fputs ($fp,"$ligne"); 
       fputs ($fp,"\n"); 
       fclose ($fp); 
    }
    ?> 
    <FORM name="citation" action="citations.php" method="post"> 
    Saisie : <INPUT NAME="ligne"><INPUT TYPE="submit"> 
    </FORM> 
    </BODY> 
    </HTML> 


    Kalamit,
    Parle à ma culasse, mon carter est malade. :)
    0