Foros del Web » Programando para Internet » PHP »

base de datos usando checkbox donde esta el error?

Estas en el tema de base de datos usando checkbox donde esta el error? en el foro de PHP en Foros del Web. -Formulario- Hola, tengo una consulta que no puedo resolver a ver si me pueden decir donde esta el error porque ya probe y no me ...
  #1 (permalink)  
Antiguo 10/12/2011, 12:22
 
Fecha de Ingreso: diciembre-2011
Ubicación: Capital Federal
Mensajes: 2
Antigüedad: 12 años, 4 meses
Puntos: 0
Información base de datos usando checkbox donde esta el error?

-Formulario-
Hola, tengo una consulta que no puedo resolver a ver si me pueden decir donde esta el error porque ya probe y no me funciona, resulta que tengo un Form con 3 checkbox comandos para guardar los datos en MYSQL, entonces que lo que sucede es que nunca me guarda el valor del checkbox y si me guarda todos los otros valores me explico? Por favor si alguien me puede dar una mano.


Código PHP:
<?php require_once('Connections/encuesta.php'); ?>
<?php
if (array_key_exists('enviar'$_POST)) {
  if (isset(
$_POST['check'])) {
    
$_POST['check'] = implode(','$_POST['check']);
    }
  else {
    
$_POST['check'] = '';
    }
  if (isset(
$_POST['check1'])) {
    
$_POST['check1'] = implode(','$_POST['check1']);
    }
  else {
    
$_POST['check1'] = '';
    }
  if (isset(
$_POST['check2'])) {
    
$_POST['check2'] = implode(','$_POST['check2']);
    }
  else {
    
$_POST['check2'] = '';
    }
  }
  
?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

$editFormAction $_SERVER['PHP_SELF'];
if (isset(
$_SERVER['QUERY_STRING'])) {
  
$editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO encuesta (Tipo, camas, ingresosanuales, edadmedia, apacheii, pregunta1, Pregunta2, cantpacientes, cantconst, incidencia, incidconstip, protocolo, prevencion, `check`, otros1, check1, otros2, check2, involucra, demorasalida, demoraprog, prolonga) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['Tipo'], "text"),
                       
GetSQLValueString($_POST['camas'], "text"),
                       
GetSQLValueString($_POST['ingresosanuales'], "text"),
                       
GetSQLValueString($_POST['edadmedia'], "text"),
                       
GetSQLValueString($_POST['apacheii'], "text"),
                       
GetSQLValueString($_POST['pregunta1'], "text"),
                       
GetSQLValueString($_POST['Pregunta2'], "text"),
                       
GetSQLValueString($_POST['cantpacientes'], "text"),
                       
GetSQLValueString($_POST['cantconst'], "text"),
                       
GetSQLValueString($_POST['incidencia'], "text"),
                       
GetSQLValueString($_POST['incidconstip'], "text"),
                       
GetSQLValueString($_POST['protocolo'], "text"),
                       
GetSQLValueString($_POST['prevencion'], "text"),
                       
GetSQLValueString($_POST['check'], "text"),
                       
GetSQLValueString($_POST['otros1'], "text"),
                       
GetSQLValueString($_POST['check1'], "text"),
                       
GetSQLValueString($_POST['otros2'], "text"),
                       
GetSQLValueString($_POST['check2'], "text"),
                       
GetSQLValueString($_POST['involucra'], "text"),
                       
GetSQLValueString($_POST['demorasalida'], "text"),
                       
GetSQLValueString($_POST['demoraprog'], "text"),
                       
GetSQLValueString($_POST['prolonga'], "text"));

  
mysql_select_db($database_encuesta$encuesta);
  
$Result1 mysql_query($insertSQL$encuesta) or die(mysql_error());
}
?>

Última edición por ccarlos_45; 10/12/2011 a las 13:12
  #2 (permalink)  
Antiguo 11/12/2011, 00:07
Avatar de truman_truman  
Fecha de Ingreso: febrero-2010
Ubicación: /home/user
Mensajes: 1.341
Antigüedad: 14 años, 2 meses
Puntos: 177
Respuesta: base de datos usando checkbox donde esta el error?

Cual es el valor de los check ? es un array en cada uno?

en todo caso yo lo haría distinto

$check = implode(',', $_POST['check']);


Luego aya abajo

GetSQLValueString($check , "text"),
__________________
la la la
  #3 (permalink)  
Antiguo 11/12/2011, 17:32
 
Fecha de Ingreso: diciembre-2011
Ubicación: Capital Federal
Mensajes: 2
Antigüedad: 12 años, 4 meses
Puntos: 0
Respuesta: base de datos usando checkbox donde esta el error?

“truman_truman” Gracias por responder pero no me funciono, algo tiene que estar mal en la base de datos, es que recién empiezo y no entiendo mucho.
igual muchas gracias.

Etiquetas: formulario
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 01:08.