How do I insert an array of a checkbox into 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 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 doing wrong? I really can't find the solution https://stackoverflow.com/questions/20176673/how-do-i-insert-multiple-checkbox-values-into-a-table
Update: SOLUTION found. the problem was that the varchar had a limit of 30 characters and when I selected several it exceeded the limit, increase the limit and that's it
Very good. I think I have the same problem as you, I have investigated the situation of the checkboxes, although there were small parts of the solutions in other topics, such as that currently in php 7 you can obtain them,
$_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 don't forget that it
MySql_*
is currently being negligible, I recommend using PDO/MySqli, see this link: How to avoid SQL injection in PHP?I hope it has helped you, greetings!
The solution to my question is in the TEST3 code line of the question statement obtained from this https://stackoverflow.com/questions/20176673/how-do-i-insert-multiple-checkbox-values-into-a- table . It didn't work for me, it was because the characters assigned to the varchar of the field were less than the text I was entering, that's why I didn't insert anything. i corrected from varchar 30 to 100 eg and it worked