jeudi 29 juillet 2021

i can't send the selected checkboxs to the database using mysqli

I am trying to send multiple checkboxes to database , i tried the following the code but it doesn't work as am new to php and am using procedural mysqli

<div class="form-group">
            <label class="checkbox-inline"><input type="checkbox" value="int" name="ch[]">Interruption de service</label>
            <label class="checkbox-inline"><input type="checkbox" value="hlp" name="ch[]">HLP</label>
            <label class="checkbox-inline"><input type="checkbox" value="gmao" name="ch[]">GMAO</label>
            <label class="checkbox-inline"><input type="checkbox" value="maj" name="ch[]">Majeur</label>
          </div>
     <button type="submit" class="btn btn-primary" name="submit">Submit</button>
          
          
          <?php
            if(isset($_POST['submit'])){
                echo "Les cases suivant sont cochez :<br>" ;
                $chk=implode(",",$_POST['ch']);
                $query="INSERT INTO `evenement` (toDo) values ('$chk')";
            }
           ?>
    
    //and also i i have condition that verified the click on submit 
    
    if (isset($_POST['submit'])) {
    $toDo=$_POST['ch'];
    $sql = "insert into `evenement` values ('','$ligne','$s_voiture','$code','$matricule','$s_conducteur','$un1','$un2','$h_debut','$h_fin','$desc','$lieu',$voie,'$meteo','$toDo')";
    
      $result = mysqli_query($con, $sql);
      if ($result) {
        echo "Information Inseree";
      } else {
        die(mysqli_error($con));
      }
    }

// and as a result in the database , when i check the column of toDO it says array




Aucun commentaire:

Enregistrer un commentaire