I need help to insert multiple values in mysql of a checkbox in a form:
- I have these checkboxes in my form
<LABEL>Extras (los que procedan):</LABEL>
<INPUT TYPE="checkbox" NAME="extras[]" VALUE="Vista Al Mar">Vista al Mar
<INPUT TYPE="checkbox" NAME="extras[]" VALUE="Piscina">Piscina
<INPUT TYPE="checkbox" NAME="extras[]" VALUE="Jardin">Jardin
<input type="checkbox" NAME="extras[]" VALUE="Quincho">Quincho
<INPUT TYPE="checkbox" NAME="extras[]" VALUE="Estacionamiento">Estacionamiento
- In my MySql table of the form I have that column as
extras = ENUM ('Ocean View', 'Pool', 'Garden', 'Quincho', 'Parking')
- This is my php code where I insert the form:
<?php
include("../conexion.php");
insertarVivienda($_POST['tipo'], $_POST['zona'], $_POST['direccion'], $_POST['ndorm'],$_POST['precio'],$_POST['tamano'],$_POST['extras[]'],$_POST['foto'],
$_POST['observaciones'],$_POST['tipo_servicio']);
function insertarVivienda($tipo,$zona,$direccion,$ndormitorios,$precio,$tamano,$extras,$foto,$observaciones,$tipo_servicio)
{
echo $query = "INSERT INTO 'vivienda' ('idvivienda', 'tipo_vivienda', 'zona', 'direccion', 'ndormitorios', 'precio', 'tamano', 'extras', 'foto', 'observaciones', 'usuario_id',tipo_servicio) VALUES ('Null', '".$tipo."', '".$zona."', '".$direccion."', '".$ndormitorios."', '".$precio."', '".$tamano."', '".$extras."', '".$foto."', '".$observaciones."','".$tipo_servicio.", '1')";
$conexion = conectar();
mysqli_query($conexion,$query) or die (mysqli_error());
}
?>
- All other data is inserted without problems, still not worth anything and I allow empty only to see what happens, but when I select 1 or more check box throws me this error:
Notice: Undefined index: extras[] in C:\xampp\htdocs\inmobiliaria\crud\insertar.php on line 6
INSERT INTO 'vivienda' ('idvivienda', 'tipo_vivienda', 'zona', 'direccion', 'ndormitorios', 'precio', 'tamano', 'extras', 'foto', 'observaciones', 'usuario_id') VALUES ('Null', 'Departamento', 'El Tabo', '', '1', '', '', '', '', '', '1')
with everything else ok, before I had no problems when I used "extras" as combo box but I need to select more than 1 extra so I thought to use checkbox ...
thank you very much.