Foros del Web » Programando para Internet » PHP »

Ayuda con checkbox y php

Estas en el tema de Ayuda con checkbox y php en el foro de PHP en Foros del Web. Hola Quisiera saber como con PHP validar si un checkbox esta activado o no, porque lo que estoy haciendo es insertar en una base de ...
  #1 (permalink)  
Antiguo 21/01/2011, 07:30
 
Fecha de Ingreso: septiembre-2010
Ubicación: Santiago, Chile
Mensajes: 47
Antigüedad: 13 años, 7 meses
Puntos: 0
Ayuda con checkbox y php

Hola

Quisiera saber como con PHP validar si un checkbox esta activado o no, porque lo que estoy haciendo es insertar en una base de datos un campo que es monto, y si esta activado el checkbox que genere el iva del monto, y si no que el campo iva quede en blanco

tengo esto
Código PHP:
Ver original
  1. if(isset($_POST['checkmonto'])){
  2.     //generar iva del monto aqui
  3. }

pero me genere este error


Parse error: parse error in C:\wamp\www\intranet\nuevaActividad.php on line 83

Saludos
  #2 (permalink)  
Antiguo 21/01/2011, 07:33
Avatar de odiseus  
Fecha de Ingreso: enero-2011
Mensajes: 109
Antigüedad: 13 años, 3 meses
Puntos: 3
Respuesta: Ayuda con checkbox y php

Y que hay supuestamente en la linea 83?
  #3 (permalink)  
Antiguo 21/01/2011, 07:55
 
Fecha de Ingreso: septiembre-2010
Ubicación: Santiago, Chile
Mensajes: 47
Antigüedad: 13 años, 7 meses
Puntos: 0
Respuesta: Ayuda con checkbox y php

en esa linea esta el codigo

if(isset($_POST['checkmonto'])){
  #4 (permalink)  
Antiguo 21/01/2011, 08:01
Avatar de odiseus  
Fecha de Ingreso: enero-2011
Mensajes: 109
Antigüedad: 13 años, 3 meses
Puntos: 3
Respuesta: Ayuda con checkbox y php

Esa linea no tiene ningun fallo, debe de ser alguna anterior.
  #5 (permalink)  
Antiguo 21/01/2011, 08:23
 
Fecha de Ingreso: septiembre-2010
Ubicación: Santiago, Chile
Mensajes: 47
Antigüedad: 13 años, 7 meses
Puntos: 0
Respuesta: Ayuda con checkbox y php

es esa linea, porque cuando la coloco con comentarios la pagina corre sin ningun problema
  #6 (permalink)  
Antiguo 21/01/2011, 08:28
Avatar de Nano_  
Fecha de Ingreso: febrero-2006
Ubicación: Bogotá, Colombia
Mensajes: 1.866
Antigüedad: 18 años, 2 meses
Puntos: 96
Respuesta: Ayuda con checkbox y php

Saludos

Seria conveniente que postearas el código que tienes ya como comenta odiseus en esa linea no esta el error
__________________
:.:Nano.:: @nano_hard - Retornando al foro
  #7 (permalink)  
Antiguo 21/01/2011, 08:28
Avatar de odiseus  
Fecha de Ingreso: enero-2011
Mensajes: 109
Antigüedad: 13 años, 3 meses
Puntos: 3
Respuesta: Ayuda con checkbox y php

No puede ser, es un if normal con una variable, no tiene nada de especial. Tiene que haber algo más por ahí
  #8 (permalink)  
Antiguo 21/01/2011, 08:35
 
Fecha de Ingreso: septiembre-2010
Ubicación: Santiago, Chile
Mensajes: 47
Antigüedad: 13 años, 7 meses
Puntos: 0
Respuesta: Ayuda con checkbox y php

La pagina la estoy haciendo en dreamweaver 8, este es el codigo para insertar

Código PHP:
Ver original
  1. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  2. {
  3.   $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
  4.  
  5.   switch ($theType) {
  6.     case "text":
  7.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  8.       break;    
  9.     case "long":
  10.     case "int":
  11.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  12.       break;
  13.     case "double":
  14.       $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
  15.       break;
  16.     case "date":
  17.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  18.       break;
  19.     case "defined":
  20.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  21.       break;
  22.   }
  23.   return $theValue;
  24. }
  25.  
  26. $editFormAction = $_SERVER['PHP_SELF'];
  27. if (isset($_SERVER['QUERY_STRING'])) {
  28.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  29. }
  30.  
  31. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  32.   $insertSQL = sprintf("INSERT INTO actividades (ot_id, actividad, monto, iva, horas_soporte) VALUES (%s, %s, %s, %s, %s)",
  33.                        GetSQLValueString($_POST['hiddenField'], "int"),
  34.                        GetSQLValueString($_POST['actividad'], "text"),
  35.                        GetSQLValueString($_POST['monto'], "int"),
  36.                        if(isset($_POST['chkIva']))
  37.                              GetSQLValueString($_POST['monto'] * 0.19, "int"),   
  38.                        GetSQLValueString($_POST['hora'].":".$_POST['minuto'], "date"));
  39.  
  40.   mysql_select_db($database_connBD, $connBD);
  41.   $Result1 = mysql_query($insertSQL, $connBD) or die(mysql_error());
  42.   $insertGoTo = "cerrarPopUp.php";
  43.   if (isset($_SERVER['QUERY_STRING'])) {
  44.     $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  45.     $insertGoTo .= $_SERVER['QUERY_STRING'];
  46.   }
  47.   header(sprintf("Location: %s", $insertGoTo));
  48. }
  #9 (permalink)  
Antiguo 21/01/2011, 08:41
Avatar de Nano_  
Fecha de Ingreso: febrero-2006
Ubicación: Bogotá, Colombia
Mensajes: 1.866
Antigüedad: 18 años, 2 meses
Puntos: 96
Respuesta: Ayuda con checkbox y php

Saludos

Revisar donde haces el insert into saque la seccion del if del sprintf, coloque un comentario para que te guies

Código PHP:
Ver original
  1. <?php
  2.  
  3. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") {
  4.     $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
  5.  
  6.     switch ($theType) {
  7.         case "text":
  8.             $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  9.             break;
  10.         case "long":
  11.         case "int":
  12.             $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  13.             break;
  14.         case "double":
  15.             $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
  16.             break;
  17.         case "date":
  18.             $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  19.             break;
  20.         case "defined":
  21.             $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  22.             break;
  23.     }
  24.     return $theValue;
  25. }
  26.  
  27. $editFormAction = $_SERVER['PHP_SELF'];
  28. if (isset($_SERVER['QUERY_STRING'])) {
  29.     $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  30. }
  31.  
  32. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  33. /***********************************************************   /
  34. //Inclui las siguientes lineas no puedes hacer un if dentro de un sprintf
  35. /************************************************************/
  36.     $monto=0;
  37.     $fecha="";
  38.     if ($_POST['chkIva']) {
  39.         $monto = GetSQLValueString($_POST['monto'] * 0.19, "int");
  40.         $fecha = GetSQLValueString($_POST['hora'] . ":" . $_POST['minuto'], "date");
  41.     }
  42.     $insertSQL = sprintf("INSERT INTO actividades (ot_id, actividad, monto, iva, horas_soporte) VALUES (%s, %s, %s, %s, %s)",
  43.                     GetSQLValueString($_POST['hiddenField'], "int"),
  44.                     GetSQLValueString($_POST['actividad'], "text"),
  45.                     GetSQLValueString($_POST['monto'], "int"),
  46.                     $monto,
  47.                     $fecha);
  48.  
  49.  
  50.     mysql_select_db($database_connBD, $connBD);
  51.     $Result1 = mysql_query($insertSQL, $connBD) or die(mysql_error());
  52.     $insertGoTo = "cerrarPopUp.php";
  53.     if (isset($_SERVER['QUERY_STRING'])) {
  54.         $insertGoTo .= ( strpos($insertGoTo, '?')) ? "&" : "?";
  55.         $insertGoTo .= $_SERVER['QUERY_STRING'];
  56.     }
  57.     header(sprintf("Location: %s", $insertGoTo));
  58. }
  59. ?>
__________________
:.:Nano.:: @nano_hard - Retornando al foro
  #10 (permalink)  
Antiguo 21/01/2011, 09:08
 
Fecha de Ingreso: septiembre-2010
Ubicación: Santiago, Chile
Mensajes: 47
Antigüedad: 13 años, 7 meses
Puntos: 0
Respuesta: Ayuda con checkbox y php

FUNCIONA!!!!!!

Muchas gracias, se pasaron, me han salvado la vida

  #11 (permalink)  
Antiguo 21/01/2011, 09:31
Avatar de Nano_  
Fecha de Ingreso: febrero-2006
Ubicación: Bogotá, Colombia
Mensajes: 1.866
Antigüedad: 18 años, 2 meses
Puntos: 96
Respuesta: Ayuda con checkbox y php

Que bueno que te halla funcionado.

Hasta Pronto
__________________
:.:Nano.:: @nano_hard - Retornando al foro

Etiquetas: checkbox
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:08.