Home > OS >  print_r($_FILES) Undefined array key
print_r($_FILES) Undefined array key

Time:06-21

I am trying to use print_r to show the data that is inserting from the form to see if the data are really sending after the submit but the outpute for the files is

"Warning: Undefined array key "actenaisss" in C:\xampp\htdocs\BEA1\insertion1.php on line 21"

here is my code:

<?php
require ("config.php");
if(isset($_POST['suiv'])){

    $typeban = $_POST['typeban'];
    $nom = $_POST['nom'];
    $prenom = $_POST['prenom'];
    $nais = $_POST['nais'];
    $lnais = $_POST['lnais'];
    $pprenom = $_POST['pprenom'];
    $mnom = $_POST['mnom'];
    $mprenom = $_POST['mprenom'];
    $actenais = $_POST['actenais'];
    $typepie = $_POST['typepie'];
    $numpi = $_POST['numpi'];
    $datedeliv = $_POST['datedeliv'];
    $delivpar = $_POST['delivpar'];
    $prof = $_POST['prof'];
    $numero = $_POST['numero'];
    $email = $_POST['email'];
    $actenaisss = $_FILES['actenaisss'];
    $piec = $_FILES['piec'];
    $resid = $_FILES['resid'];

       
       print_r($typeban);
       echo "<br>";
       print_r($nom);
       echo "<br>";
       print_r($prenom);
       echo "<br>";
       print_r($nais);
       echo "<br>";
       print_r($lnais);
       echo "<br>";
       print_r($pprenom);
       echo "<br>";
       print_r($mnom);
       echo "<br>";
       print_r($mprenom);
       echo "<br>";
       print_r($actenais);
       echo "<br>";
       print_r($typepie);
       echo "<br>";
       print_r($numpi);
       echo "<br>";
       print_r($datedeliv);
       echo "<br>";
       print_r($delivpar);
       echo "<br>";
       print_r($prof);
       echo "<br>";
       print_r($numero);
       echo "<br>";
       print_r($email);
       echo "<br>";
       print_r($actenaisss);
       echo "<br>";
       print_r($piec);
       echo "<br>";
       print_r($resid);
}
?>

Here is my form:

<!DOCTYPE html>
<html>
<head>
    <title>Formulaire compte depot</title>
</head>
<body>
    <form enctype="multipart/form-data" method="post" action="insertion1.php" >
       <table>
             <tr> <td><input type="checkbox" name="prsnphysique" value="Je suis une personne physique." required="true">Je suis une personne physique </td>
             <td> <label>Type de compte bancaire</label>
                     <select name="typeban">
                            <option>Compte depot</option>
                            <option>Compte CEDAC</option>
                            <option>Compte personnel BEA</option>
                     </select></td></tr>
       <tr>
        <td>
                     <label>Nom</label>
            <input type="text" name="nom" placeholder="Nom" required="true">
        </td>
        <td>
                     <label>Prenom</label>
            <input type="text" name="prenom" placeholder="Prenom" required="true">
        </td>
       </tr>
       <tr>
        <td>
                     <label>Date de naissance</label>
            <input type="date" name="nais" placeholder="Date de naissance" required="true">
        </td>
        <td>
                     <label>Lieu de naissance</label>
            <input type="text" name="lnais" placeholder="Lieu de naissance" required="true">
        </td>
       </tr>
       <tr>
        <td>
                     <label>Prenom du pere</label>
            <input type="text" name="pprenom" required="true" placeholder="Prenom du père">
        </td>
        <td>
                     <label>Nom de la mere</label>
            <input type="text" name="mnom" required="true" placeholder="Nom de la mère">
        </td>
       </tr>
       <tr>
        <td>
                     <label>Prenom de la mere</label>
            <input type="text" name="mprenom" required="true" placeholder="Prenom de la mère">
        </td>
        <td>    
                     <label>Numero de l'acte de naissance</label>
                   <input type="number" name="actenais" required="true" placeholder="Numero de l'acte de naissance">
        </td>
       </tr>
       <tr>
        <td>
            <label>Piece d'identite presente</label>
            <select name="typepie">
                <option>Carte d'identite</option>
                <option>Permis de conduire</option>
                <option>Passeport</option>
            </select>
        </td>
        <td>
                     <label>Numero de la piece d'identite</label>
            <input type="number" name="numpi" required="true" placeholder="Numero de la piece d'identite">
        </td>
       </tr>
       <tr>
        <td>
                     <label>Delivree le</label>
            <input type="date" name="datedeliv" required="true" placeholder="Delivree le">
        </td>
        <td>
                     <label>delivree par</label>
            <input type="text" name="delivpar" required="true" placeholder="Delivree par">
        </td>
       </tr>
       <tr>
        <td>
                     <label>Profession</label>
            <input type="text" name="prof" required="true" placeholder="Profession">
        </td>
        <td>
                     <label>Numero de telephone</label>
            <input type="number" name="numero" required="true" placeholder="Numero de telephone">
        </td>
       </tr>
       <tr>
        <td>
                     <label>E-mail</label>
            <input type="email" name="email" required="true" placeholder="E-mail">
        </td>
       </tr>
       <tr>
              <td>
                     <label>Pieces justificatifs</label><br><br>
                     Acte de naissance  <input type="file" name="actenaisss" required="true"><br><br>
                     Piece d'identite  <input type="file" name="piec" required="true"><br><br>
                     Certificat de residence/ Facture d'electricite<br>Hebergement/ Contrat location  <input type="file" name="resid" required="true">
              </td>
       </tr>
   </table>
       <input type="submit" name="suiv" value="Suivant">
    </form>
</body>
</html>

Please help me with this, Thank you

CodePudding user response:

I tried your code and it all prints well. I guess you did not upload all files in the corresponding file input. You should check for all the variables first with isset and return false if any required values are required.

  • Related