Ver Mensaje Individual
  #10 (permalink)  
Antiguo 30/07/2012, 20:00
marce_vampira
 
Fecha de Ingreso: junio-2012
Ubicación: En Chile :D
Mensajes: 44
Antigüedad: 14 años, 4 meses
Puntos: 0
Respuesta: Guardar varios arrays de checkbox

Estimados, yo he venido dandole vueltas a algo similar... tengo una tabla dinamica que genera un checkbox por cada registro de la base de datos...

Mi problema se presenta al momento de guardar, solo me guarda uno de los seleccionados, no los otros... aca les dejo el codigo a ver si se puede hacer algo, ya que en codigo no me manejo mucho, y todo esta hecho en dreamweaver... muchas gracias por su ayuda!!!!

Código PHP:
<?php require_once('Connections/formulario.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_update"])) && ($_POST["MM_update"] == "form1")) {
  
$updateSQL = sprintf("UPDATE falla_cocina SET opcion=%s WHERE id1=%s",
                       
GetSQLValueString($_POST['idcat[]'], "text"),
                       
GetSQLValueString($_POST['idcat[]'], "int"));

  
mysql_select_db($database_formulario, $formulario);
  
$Result1 = mysql_query($updateSQL, $formulario) or die(mysql_error());
}

mysql_select_db($database_formulario, $formulario);
$query_Recordset1 = "SELECT * FROM falla_cocina";
$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>
<?
$rows
=mysql_query("select * from falla_calefon") or die(mysql_error());
?>
<form action="<?php echo $editFormAction; ?>" name="form1" id="form1" method="POST">
    <table>
        <tr>
            <th>
                ID
            </th>
            <th>
                Falla
            </th>
        </tr>
       <?
       
while($row=mysql_fetch_array($rows)){
       
?>
        <tr>
            <td><?php echo $row['id']?><input type="checkbox" name="idcat[]" id="idcat" value="<?php echo $row['id'];?>" /></td>
            <td><?php echo $row['id']?></td>
        </tr>
        <?php 
       
}
        
?>
        <tr>
            <td colspan="2">
                <input type="submit" value="Modificar" />
            </td>
        </tr>
     </table>
    <input type="hidden" name="MM_update" value="form1" />
</form>
</body>
</html>
<?php
mysql_free_result
($Recordset1);
?>