Ver Mensaje Individual
  #3 (permalink)  
Antiguo 03/05/2012, 09:00
fcosun
 
Fecha de Ingreso: octubre-2011
Mensajes: 153
Antigüedad: 12 años, 6 meses
Puntos: 7
Respuesta: tomar datos del formulario con checkbox y enviar a DB

Aca tienes un ejemplo de como pasar datos con los checkbox.

Para recibir los datos enviados por un checkbox se realiza de la siguiente forma:

Ejemplo 1
$mivalor = $_REQUEST['check1'] //aqui va el name="check1" del html

Ejemplo 2
$mivalor = $_POST['check1']

Ejemplo 3
$mivalor = $_GET['check1']

Ejemplo practico:

index.html

Código HTML:
Ver original
  1.     <head>
  2.         <title>Problema</title>
  3.     </head>
  4.  
  5. <form action="checkbox.php" method="post">
  6.     Ingrese primer valor:
  7.     <input type="text" name="valor1">
  8.     <br>
  9.     Ingrese segundo valor:
  10.     <input type="text" name="valor2">
  11.     <br>
  12.     <input type="checkbox" name="check1">sumar
  13.     <br>
  14.     <input type="checkbox" name="check2">restar
  15.     <br>
  16.     <input type="submit" name="operar">
  17. </form>
  18.  
  19. </body>
  20. </html>

checkbox.php

Código PHP:
Ver original
  1. <html>
  2. <head>
  3. <title>Problema</title>
  4. </head>
  5. <body>
  6.  
  7. <?php
  8. if (isset($_REQUEST['check1']))
  9. {
  10.   $suma=$_REQUEST['valor1'] + $_REQUEST['valor2'];
  11.   echo "La suma es:".$suma."<br>";
  12. }
  13. if (isset($_REQUEST['check2']))
  14. {
  15.   $resta=$_REQUEST['valor1'] - $_REQUEST['valor2'];
  16.   echo "La resta es:".$resta;
  17. }
  18. ?>
  19.  
  20. </body>
  21. </html>
__________________
Mi mail: [email protected]