Les dejo mi consulta, vengo ya hace harto tiempo dandole vueltas a esto, y como mis conocimientos de codigo son casi nulos solo me manejo con Dreamweaver para hacer cosas... tengo una tabla dinamica, la cual por cada valor me entrega un checkbox. Hasta ahi, todo bien, el problema se presenta cuando quiero marcar mas de un checkbox, ya que en vez de guardar todos los registros marcados, solo me guarda uno.
Hasta aqui, espero haber explicado bien lo que tengo y donde esta mi problema, a lo cual tengo que agregar (y que tampoco se como hacer, ni se si es que puede hacerse) es que cada valor de los checkbox seleccionados sean guardados separados por una coma.
aca les dejo mi codigo, espero haber sido clara y que no sea complicado de solucionar.
Muchas gracias a todos!!!
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 ((foreach($_POST['idcat'] as $item)) {
echo $item;
}
$updateSQL = sprintf("UPDATE falla_cocina SET opcion=%s WHERE id1=%s",
GetSQLValueString($_POST['idcat'][0], "text"),
GetSQLValueString($_POST['idcat'][1], "int"));
mysql_select_db($database_formulario, $formulario);
$Result1 = mysql_query($insertSQL, $formulario) or die(mysql_error());
}
?>
<!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 name="form1" id="form1" action="<?php echo $editFormAction; ?>" 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_insert" value="form1" />
</form>
</body>
</html>