0
I have a form with a checkbox group (equal below) and would like when selecting the values, insert a row in the SQL table for each selected checkbox:
<form>
<input type="hidden" id="id_pedido" value="123">
<div>
<input class="uk-checkbox" type="checkbox" value="16.15"> Adicional 1
</div>
<div>
<input class="uk-checkbox" type="checkbox" value="23.75"> Adicional 2
</div>
<button id="concluir" name="concluir" class="uk-button uk-button-primary" type="submit">Concluir</button>
</form>
Then when selecting the 2 values, the MYSQL table (cv_contratos_additional) should look like this:
id | id_pedido | valor | servico
1 | 123 | 16.15 | Adicional 1
2 | 123 | 23.75 | Adicional 2
This is what I have so far, the checkbox part and I need to know how to "break" the value and name of the service:
<body>
<?php
if(isset($_POST['concluir'])){
$sql = "INSERT INTO cv_contratos_adicinoais (id_pedido, valor, servico)
VALUES ('".$_POST["id_pedido"]."','".$_POST["valor"]."','".$_POST["servico"]."')";
}
?>
<form method="post">
<input type="hidden" name="id_pedido" id="id_pedido" value="123">
<div>
<input class="uk-checkbox" type="checkbox" value="16.15"> Adicional 1
</div>
<div>
<input class="uk-checkbox" type="checkbox" value="23.75"> Adicional 2
</div>
<button id="concluir" name="concluir" class="uk-button uk-button-primary" type="submit">Concluir</button>
</form>
</body>
and what have you tried to do? by the way, which server language is using?
– Ricardo Pontual
to using php, I tried to use the INSERT INTO cv_contratos_additional, then it inserts, the problem is that from this comes all checkbox as a single value and not in separate lines
– Leandro Marzullo
you need to put your complete code, the php you are using to insert and to assemble the page otherwise it will be difficult to help
– Ricardo Pontual
edited, and put there what I have so far
– Leandro Marzullo
put name in checkbox and recover with post, and alias where is the mysqli_query($sql) in your code?
– Samuel Ives