1
I am creating a system and how could I store multiple checkbox and inputs in mysql ? I know I can do it this way but only if it goes to a column , in my case are four as could do
if(!Empty($_POST['genero']) && Count($_POST['genero']) ){ $items = implode(',', $_POST['gender']);
that’s my code
<?php
error_reporting(-1);
ini_set('display_errors', 'On');
//Criar a conexao
$link = new mysqli ("localhost", "root", "", "peixaria");
if($link->connect_errno){
echo"Nossas falhas local experiência ..";
exit();
}
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$numero_mesa = $_POST['numero_mesa'];
$pedido_refeicao = $_POST['pedido_refeicao'];
$num_refeicao = $_POST['num_refeicao'];
$pedido_bebida = $_POST['pedido_bebida'];
$num_bebida = $_POST['num_bebida'];
$sql="INSERT INTO mpedido(numero_mesa,pedido_refeicao,num_refeicao,pedido_bebida,num_bebida) VALUES('$numero_mesa','$pedido_refeicao','$num_refeicao','$pedido_bebida','$num_bebida')";
$resultado_pedido = mysqli_query($link,$sql);
}
?>
<fieldset>
<div class="pedidos">
<form method="post" action="secao.php">
<table >
<tr>
<td colspan="4" width="100">
<span>Mesa</span>
<input type="text" id="numero_mesa" name="numero_mesa">
<label>
<span>Comanda:</span>
</label>
<br>
<br>
</td>
</tr>
<tr>
<td width="280" bgcolor="#00BFFF">Refeição</td>
<td width="70" bgcolor="#00BFFF">Quantidade</td>
<td width="150" bgcolor="#1E90FF">Bebida</td>
<td width="70" bgcolor="#1E90FF">Quantidade</td>
</tr>
<tr>
<td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Costela de Tambaqui sem Espinha">Costela de Tambaqui sem Espinha</td>
<td width="70"><input type="text" name="num_refeicao[]" size="7"></td>
<td width="150"><input type="checkbox" name="pedido_bebida[]" value="Fanta Laranja 1l">Fanta Laranja 1l</td>
<td width="70"><input type="text" name="num_bebida[]" size="7"></td>
</tr>
<tr>
<td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Lombo de Tambaqui Frito sem Espinha">Lombo de Tambaqui Frito sem Espinha</td>
<td width="70"><input type="text" name="num_refeicao[]" size="7"></td>
<td width="150"><input type="checkbox" name="pedido_bebida[]" value="Fanta Laranja 2l">Fanta Laranja 2l</td>
<td width="70"><input type="text" name="num_bebida[]" size="7"></td>
</tr>
<tr>
<td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Caldeirada de Tambaqui sem Espinha">Caldeirada de Tambaqui sem Espinha</td>
<td width="70"><input type="text" name="num_refeicao[]" size="7"></td>
<td width="150"><input type="checkbox" name="pedido_bebida[]" value="Cola Cola 1l">Cola Cola 1l</td>
<td width="70"><input type="text" name="num_bebida[]" size="7"></td>
</tr>
<tr>
<td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Caldeirada de Tucunaré">Caldeirada de Tucunaré</td>
<td width="70"><input type="text" name="num_refeicao[]" size="7"></td>
<td width="150"><input type="checkbox" name="pedido_bebida[]" value="Cola Cola 2l">Cola Cola 2l</td>
<td width="70"><input type="text" name="num_bebida[]" size="7"></td>
</tr>
<tr>
<td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Peixe no Tucupi com Camarão">Peixe no Tucupi com Camarão</td>
<td width="70"><input type="text" name="num_refeicao[]" size="7"></td>
<td width="150"><input type="checkbox" name="pedido_bebida[]" value="Bare 2l">Bare 2l</td>
<td width="70"><input type="text" name="num_bebida[]" size="7"></td>
</tr>
<tr>
<td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Escabeche de Pirarucu">Escabeche de Pirarucu</td>
<td width="70"><input type="text" name="num_refeicao[]" size="7"></td>
<td width="150"><input type="checkbox" name="pedido_bebida[]" value="Fanta Uva">Fanta Uva</td>
<td width="70"><input type="text" name="num_bebida[]" size="7"></td>
</tr>
<tr>
<td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Escabeche de Tambaqui">Escabeche de Tambaqui</td>
<td width="70"><input type="text" name="num_refeicao[]" size="7"></td>
<td width="150"><input type="checkbox" name="pedido_bebida[]" value="Fanta Laranja">Fanta Laranja</td>
<td width="70"><input type="text" name="num_bebida[]" size="7"></td>
</tr>
<tr>
<td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Escabeche de Tucunaré">Escabeche de Tucunaré</td>
<td width="70"><input type="text" name="num_refeicao[]" size="7"></td>
<td width="150"><input type="checkbox" name="pedido_bebida[]" value="Sprit">Sprit</td>
<td width="70"><input type="text" name="num_bebida[]" size="7"></td>
</tr>
<tr>
<td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Tucunaré Frito">Tucunaré Frito</td>
<td width="70"><input type="text" name="num_refeicao[]" size="7"></td>
<td width="150"><input type="checkbox" name="pedido_bebida[]" value="Cola Cola">Cola Cola</td>
<td width="70"><input type="text" name="num_bebida[]" size="7"></td>
</tr>
<tr>
<td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Sardinha Frita">Sardinha Frita</td>
<td width="70"><input type="text" name="num_refeicao[]" size="7"></td>
<td width="150"><input type="checkbox" name="pedido_bebida[]" value="Cola Cola zero">Cola Cola zero</td>
<td width="70"><input type="text" name="num_bebida[]" size="7"></td>
</tr>
<tr>
<td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Jaraqui Frito">Jaraqui Frito</td>
<td width="70"><input type="text" name="num_refeicao[]" size="7"></td>
<td width="150"><input type="checkbox" name="pedido_bebida[]" value="Guaraná Antarctica">Guaraná Antarctica</td>
<td width="70"><input type="text" name="num_bebida[]" size="7"></td>
</tr>
<tr>
<td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Pacu Frito">Pacu Frito</td>
<td width="70"><input type="text" name="num_refeicao[]" size="7"></td>
<td width="150"><input type="checkbox" name="pedido_bebida[]" value="Guaraná Baré">Guaraná Baré</td>
<td width="70"><input type="text" name="num_bebida[]" size="7"></td>
</tr>
<tr>
<td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Filé de Pirarucu Frito">Filé de Pirarucu Frito</td>
<td width="70"><input type="text" name="num_refeicao[]" size="7"></td>
<td width="150"><input type="checkbox" name="pedido_bebida[]" value="Suco Manga">Suco Manga</td>
<td width="70"><input type="text" name="num_bebida[]" size="7"></td>
</tr>
<tr>
<td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Filé de Pirarucu a Milanesa">Filé de Pirarucu a Milanesa</td>
<td width="70"><input type="text" name="num_refeicao[]" size="7"></td>
<td width="150"><input type="checkbox" name="pedido_bebida[]" value="Suco Pessego">Suco Pessego</td>
<td width="70"><input type="text" name="num_bebida[]" size="7"></td>
</tr>
<tr>
<td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Guisado de Pirarucu">Guisado de Pirarucu</td>
<td width="70"><input type="text" name="num_refeicao[]" size="7"></td>
<td width="150"><input type="checkbox" name="pedido_bebida[]" value="Suco Goiaba">Suco Goiaba</td>
<td width="70"><input type="text" name="num_bebida[]" size="7"></td>
</tr>
<tr>
<td width="280"></td>
<td width="70"></td>
<td width="150"><input type="checkbox" name="pedido_bebida[]" value="Suco Uva">Suco Uva</td>
<td width="70"><input type="text" name="num_bebida[]" size="7"></td>
</tr>
<tr>
<td width="280"></td>
<td width="70"></td>
<td width="150"><input type="checkbox" name="pedido_bebida[]" value="Suco Maracujá">Suco Maracujá</td>
<td width="70"><input type="text" name="num_bebida[]" size="7"></td>
</tr>
<tr>
<td width="280"></td>
<td width="70"></td>
<td width="150"><input type="checkbox" name="pedido_bebida[]" value="Suco Laranja">Suco Laranja</td>
<td width="70"><input type="text" name="num_bebida[]" size="7"></td>
</tr>
<tr>
<td width="280"></td>
<td width="70"></td>
<td width="150"><input type="checkbox" name="pedido_bebida[]" value="Suco Caju">Suco Caju</td>
<td width="70"><input type="text" name="num_bebida[]" size="7"></td>
</tr>
<tr>
<td width="280"></td>
<td width="70"></td>
<td width="150"><input type="checkbox" name="pedido_bebida[]" value="Agua Mineral">Agua Mineral</td>
<td width="70"><input type="text" name="num_bebida[]" size="7"></td>
</tr>
<tr>
<td width="280"></td>
<td width="70"></td>
<td width="150"><input type="checkbox" name="pedido_bebida[]" value="Agua com Gas">Agua com Gas</td>
<td width="70"><input type="text" name="num_bebida[]" size="7"></td>
</tr>
<tr>
<td width="280"></td>
<td width="70"></td>
<td width="150"><input type="checkbox" name="pedido_bebida[]" value="Cerveja em Lata">Cerveja em Lata</td>
<td width="70"><input type="text" name="num_bebida[]" size="7"></td>
</tr>
<tr>
<td width="280"></td>
<td width="70"></td>
<td width="150"><input type="checkbox" name="pedido_bebida[]" value="Limonada Natural">Limonada Natural</td>
<td width="5"><input type="text" name="num_bebida[]" size="7"></td>
</tr>
<tr>
<td colspan="4" width="100">
<br>
<button class="btn" type="submit">Fazer Pedido</button>
</td>
</tr>
</table>
</div>
</fieldset>
</form>
Each
checkbox
must possess aname
different, you can choose a code to facilitate, at the time of saving I suggest you save in a field only as aarray json
for example, the quantity may work the same way, so at the time of pulling the order can bring only the listed items and the amounts referred.– MarceloBoni
Publish the HTML snippet from
input
checkbox– Carlos Fernandes
because it is every checkbox has different name , more would like to know how to implement them in php
– allan araujo
I’m a little confused about what you want, but it’s a good option @Marcelobonifazio gave you. I would suggest something more complex, using an order table, one for meals and one for drink and create their relationship.
– Carlos Fernandes