I am saving a PHP$Sucursal
Array ( ) in my database but when sending it to the Database Table it is saved as an Array and when I bring it and want to use a single one it says that it is an Array, of course before sending it if I get the data as Arrayvar_dump
I am saving it as follows:
//Usuario Logeado Datos//
$ConsultaSQL = "SELECT * FROM owner WHERE owner_email='$email' ";
$EjecutarConsulta = mysqli_query($con,$ConsultaSQL);
$respuesta = mysqli_fetch_array($EjecutarConsulta);
$ID_Consultado = $respuesta['owner_id'];
$Correo = $respuesta['owner_email'];
// Usuario Logeado Datos //
$Sucursal = $_POST['id'];
//var_dump($Sucursal);
$NombreBono = $_POST['NombreBono'];
$Monto = $_POST['Monto'];
$Comentarios = $_POST['Comentarios'];
$fecha = date('Y-m-d H:i:s');
if (empty($NombreBono))
{
}
else{
echo '<script type="text/javascript">';
echo 'setTimeout(function () { swal.fire("Bono añadido correctamente","Hecho!","Realizado");';
echo '}, 500);</script>';
$ejecucion = "INSERT INTO `Bonos_Creados` (`NombreBono`, `Monto`, `id_QueinCreo`, `QuienCreo` ,`Fecha`, `Comentario`,`RegionesDisponibles`) VALUES ('$NombreBono', '$Monto', '$ID_Consultado', '$Correo', '$fecha', '$Comentarios','$Sucursal')";
$validacion = mysqli_query($con,$ejecucion);
//echo("Error description: " . mysqli_error($con));
}
and this is the HTML part (I have no problem with this but in case it helps)
//Consulta de las Regiones Disponibles//
$ConsultaRegiones = "SELECT * FROM regiones";
$EjecutarConsultaRegiones = mysqli_query($con,$ConsultaRegiones);
while($row = mysqli_fetch_array($EjecutarConsultaRegiones)){
echo'<label><input type="checkbox" name="id['.$row['id'].']" id="cbox1" value="'. $row['nombre'].'"> '. $row['nombre'].' </label><br>';
//echo'<label>'. $row['nombre'].'</label>';
}
As they say here :
Which translated would be:
So, to store an array you can cast it to
json
viajson_encode($array)
( documentation ) and store it that way, and when you extract the data you convert it back toarray
viajson_decode($json_de_la_base_de_datos)
( documentation ).Similarly, it is also common, although not as modern or widespread as json , to use the
serialize()
/ functionsunserialize()
to store arrays of serialized text-mode data.Currently mysql directly supports the type
json
: