[I´ve edited this whole post in order to get the whole script printed. I´ve posted a similar shorter version because I thought it could be easier because of the spanish... but of course... it wouldn´t...]
I have this form:
<b>3. Selecciona una opción</b><br>
<input type ="checkbox" name="servicios[]" value="uno">Un sólo servicio<br>
<input type ="checkbox" name="servicios[]" value="dos">Dos servicios<br>
<input type ="checkbox" name="servicios[]" value="tres">Tres o más<br>
And to get what the users selected I use:
$servicios = $_POST['servicios'];
if(isset($servicios)){
foreach ($servicios as $servicio) {
echo $x."<br>";
}
}
Now, I have a database, and with a switch, I get the database equivalent of the element the user selected:
$consulta=mysqli_query($conexion,$query)
if($_SERVER['REQUEST_METHOD']=='POST') {
while($datosdelabase=mysqli_fetch_assoc($consulta)){
if(isset($servicios)){
foreach ($servicios as $servicio) {
switch ($servicio) {
case 'uno':
$servicios=$datosdelabase['uno'];
break;
case 'dos':
$servicios=$datosdelabase['dos'];
break;
case 'tres':
$servicios=$datosdelabase['tres'];
break;
}
echo "Servicios:".$servicio.": ".$servicios."<br>";
}
}
...
Inside the database, I´ve got each column with integer values.
That way if the user selects ie. uno. I get "Un sólo servicio" with $servicio and 1 with $servicios (because that´s what I´ve got from the database.
Now when I try to get the type, I get a string and not an array? Why is that?
echo gettype($servicios); // string
var_dump($servicios); // returns: string(2) "Two"
$s? How did you create it?$s = $_POST['s']var_dump($s)?