Ver Mensaje Individual
  #9 (permalink)  
Antiguo 05/03/2013, 01:33
TANIA1993
 
Fecha de Ingreso: julio-2009
Mensajes: 11
Antigüedad: 14 años, 9 meses
Puntos: 1
Respuesta: Guardar Checkbox seleccionados en una base de datos.

Hice esto para ti, creo que es lo que buscas.

meses.php

Código PHP:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Para Forosdelweb.com</title>
  6. </head>
  7.  
  8. <body>
  9. <?php @$badera=$_POST['bandera'];
  10. //si el formulario se envio
  11. if ($badera==1)
  12. {
  13.     echo '<h2>Seleccionaste los siguientes meses:</h2><br>';
  14.     ///verificamos que lo que se envio fue un array
  15.     if(is_array($_POST['checkbox']))
  16.     {
  17.         // realizamos el ciclo
  18.         while(list($key,$value) = each($_POST['checkbox']))
  19.         {
  20.             ///imprimimos el valor del actual checkbox
  21.             echo $value.'<br>';
  22.         }
  23.     }
  24. }
  25. //si no se ha enviado el formulario
  26. else
  27. {
  28. ?>
  29. <strong>Selecciona los meses de año que quieras:</strong><br>
  30. <form id="form1" name="form1" method="post" action="">
  31.   <p>Enero
  32.     <input name="checkbox[]" type="checkbox" id="checkbox" value="Enero" /><br>
  33.     Febrero
  34.     <input name="checkbox[]" type="checkbox" id="checkbox" value="Febrero" /><br>
  35.     Marzo
  36.     <input  name="checkbox[]" type="checkbox" id="checkbox" value="Marzo" /><br>
  37.     Abril
  38.     <input name="checkbox[]" type="checkbox" id="checkbox" value="Abril" /><br>
  39.     Mayo
  40.     <input name="checkbox[]" type="checkbox" id="checkbox" value="Mayo" /><br>
  41.     Junio
  42.     <input name="checkbox[]" type="checkbox" id="checkbox" value="Junio" /><br>
  43.     Julio
  44.     <input name="checkbox[]" type="checkbox" id="checkbox" value="Julio" /><br>
  45.     Agosto
  46.     <input name="checkbox[]" type="checkbox" id="checkbox" value="Agosto" /><br>
  47.     Septiembre
  48.     <input name="checkbox[]" type="checkbox" id="checkbox" value="Septiembre" /><br>
  49.     Octubre
  50.     <input name="checkbox[]" type="checkbox" id="checkbox" value="Octubre" /><br>
  51.     Noviembre
  52.     <input name="checkbox[]" type="checkbox" id="checkbox" value="Noviembre" /><br>
  53.     Diciembre
  54.     <input name="checkbox[]" type="checkbox" id="checkbox" value="Diciembre" /><br>
  55.    </p>
  56.   <p>
  57.     <input type="submit" name="button" id="button" value="Mostar Meses Marcados." />
  58.     <input name="bandera" type="hidden" id="bandera" value="1" />
  59.   </p>
  60. </form>
  61. <?php }?>
  62. </body>
  63. </html>