lundi 25 juillet 2016

Insert query in DB from checkbox count

I have some checkboxes in my HTML, I want when the user chooses for example 6 checkboxes, it will be saved in DB as 1 for the first checkbox, 2 for the second .... 6 for the last checked.

   foreach ($tape as $tap){
   //some variables

// I have tried this but it gives me 1 everytime. 
    $i = 1;
    $i = sprintf('%02d', $i);
  $array = array($the_date, $i);
  $ref = implode(".Tape.", $array); // for 2016_73_98.Tape.01


              $stmt = $pdo->prepare("INSERT INTO test (server, tape, 'date', reference, tape_name) VALUES (:server, :tape, :the_date, :reference, :tape_name)");
               $stmt->bindParam(':server', $server);
               $stmt->bindParam(':tape', $tap);
               $stmt->bindParam(':the_date', $the_date);
               $stmt->bindParam(':reference', $my_tape);

               $stmt->bindParam(':tape_name', $ref);

             $result = $stmt->execute();

$i++;
               }

I tried a for loop with the $count which counts how many checked elements, but it inserts 6 times the same choice for each of the 6 inputs... fair enough.




Aucun commentaire:

Enregistrer un commentaire