How to insert multiple values of a checkbox in a table

1

I insert an array of a checkbox in a mysql table

 [seleccionael25] => Array
    (
        [0] => Oximetros de pulso
        [1] => Linterna (Penlights)
        [2] => Repuestos Littmann
        [3] => Doppler fetal
        [4] => Martillo de refeljos
        [5] => Cubre-Fonendos
        [6] => Tensiometros
        [7] => Equipo de organos
        [8] => Otros accesorios
        [9] => Batas Greys Anatomy
    )

I have used these codes without success

Test1 $articulo = $_POST[ 'seleccionael25'][0] ."-". $_POST['seleccionael25'][1] ."-". $_POST['seleccionael25'][2] ."-". $_POST['seleccionael25'][3] ."-". $_POST['seleccionael25'][4] ."-". $_POST['seleccionael25'][5] ."-". $_POST['seleccionael25'][6] ."-". $_POST['seleccionael25'][7] ."-". $_POST['seleccionael25'][8] ."-". $_POST['seleccionael25'][9]; //no funciona

Test2 $articulo = $_POST[ 'seleccionael25'] //Inserta unicamente la palabra "array"

Test3 $articulo = implode(',', $_POST['seleccionael25']); //No me funciona

Test4 $checkbox = array("seleccionael25" => $_POST[seleccionael25]);// codigo obtenido en jotform
$articulo  = implode(',', $checkbox['seleccionael25']); //Test4

In the insert it is ok but it does not insert the array

$conexion->query( "INSERT INTO $tabla_db1 (pedido, seleccionael25, ......mas items) VALUES ('$pedido','$articulo', mas items)" );

Can someone tell me what I'm failing? I really do not give with the solution link

Update: SOLUTION found. the problem was that the varchar had a limit of 30 characters and when you selected several you went beyond the limit, increase the limit and you are ready

    
asked by Daniel 19.06.2017 в 03:35
source

2 answers

0

The solution to my question is in the TEST3 code line of the statement of the question obtained from this link . It did not work for me, it was because it was because the characters assigned to the varchar of the field were smaller than the text that was entering, so it did not insert anything. corregí de varchar 30 a 100 p ex and I work

    
answered by 21.06.2017 / 07:03
source
1

Very good. I think I have the same problem as you, I researched the situation on the checkbox, although there were small parts of the solutions on other issues, such as that currently in php 7 you can get the $_POST there are two options:

$check_value = isset($_POST['mi_nombre_del_checkbox']) ? 1 : 0;

From PHP 7 Null coalescing operator

$check_value = $_POST['mi_nombre_del_checkbox'] ?? 0;

Also do not forget that currently MySql_* is being negligible, I recommend using PDO / MySqli, see in this link: How to avoid SQL injection in PHP ?

I hope it has helped you, regards!

    
answered by 19.06.2017 в 15:04