Send Selected Checkboxes

0

I looked up some questions here on the site, but I could not quite understand. I have several checkboxes like this:

<td>
    <label class="ls-label-text">
        <input type="checkbox" name="adicional" value="L. Ninho" id="2.00">
        L. Ninho
    </label>
</td>
<td>
    <label class="ls-label-text">
        <input type="checkbox" name="adicional" value="Kit Kat" id="2.50">
        Kit Kat
    </label>
</td>
<td>
    <label class="ls-label-text">
        <input type="checkbox" name="adicional" value="Confete" id="2.00">
        Confete
    </label>
</td>

In a form, and I send that data to the database, only when I send it, it just sends a checkbox , it does not send all the selected ones.

My action code is this:

<?php
include "../../lib/inc_con.php";
session_start();
$mesa = $_POST['mesa'];
$tamanho = $_POST['tamanho'];
$quantidade = $_POST['qtd'];
$adicional = $_POST['adicional'];
$hiddentotal = $_POST['hiddentotal'];
$data = date('Y-m-d H:i:s');
$produto_id1 = $_POST['produto_id1'];
$atendente_id = $_SESSION['id'];

$sql = mysql_query("INSERT INTO pedidos (mesa, tamanho, qtd, adicional, hiddentotal, data, produto_id1, atendente_id) values ('$mesa', '$tamanho', '$quantidade', '$adicional', '$hiddentotal', '$data', '$produto_id1', '$atendente_id')") or die (mysql_error());

?>
    
asked by anonymous 30.10.2015 / 17:35

1 answer

2

Change the name attribute of your checkbox to:

<input type="checkbox" name="adicional[]" value="Confete" id="2.00">

So PHP will receive an array of objects, at the time of receiving normal receive:

$ _ POST ['additional']

Give var_dump to understand how these values are received.

I hope it helps, hugs

    
30.10.2015 / 17:38