Ver Mensaje Individual
  #1 (permalink)  
Antiguo 11/06/2012, 08:14
chumy_
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
guardar varios checkbox

Hola, como estan?...

Necesito saber si es posible tener varios checkbox clickeados y guardarlos todos como un solo valor para una tabla de la base de datos.

Les doy lo que tengo, y si se puede mejorar...

Código PHP:
<?php require_once('Connections/formulario.php'); ?>
<?php 
require_once('Connections/localhost.php'); ?>
<?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 prueba (prueba) VALUES (%s)",
                       
GetSQLValueString($_POST['obs'], "text"));

  
mysql_select_db($database_localhost$localhost);
  
$Result1 mysql_query($insertSQL$localhost) or die(mysql_error());
}

mysql_select_db($database_formulario$formulario);
$query_Recordset1 "SELECT * FROM falla_calefon";
$Recordset1 mysql_query($query_Recordset1$formulario) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin título</title>
</head>

<body>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction?>">
  <label for="obs3"></label>
  <table border="1">
    <tr>
      <td>&nbsp;</td>
      <td>falla_calefon</td>
    </tr>
    <?php do { ?>
      <tr>
        <td><input name="obs" type="checkbox" id="obs" value="<?php echo $row_Recordset1['falla_calefon']; ?>" />
        <label for="obs"></label></td>
        <td><?php echo $row_Recordset1['falla_calefon']; ?></td>
      </tr>
      <?php } while ($row_Recordset1 mysql_fetch_assoc($Recordset1)); ?>
  </table>
  <p>
    <input type="submit" name="enviar" id="enviar" value="Enviar" />
  </p>
  <input type="hidden" name="MM_insert" value="form1" />
</form>
</body>
</html>
<?php
mysql_free_result
($Recordset1);
?>
Como se dan cuenta, aqui aparece un checkbox por cada valor de la tabla, pero al momento de guardar los datos en la otra base de datos solo me guarda uno de los varios marcados...

Gracias ;)