Ver Mensaje Individual
  #3 (permalink)  
Antiguo 06/10/2010, 13:56
Avatar de blonder413
blonder413
 
Fecha de Ingreso: octubre-2010
Mensajes: 58
Antigüedad: 13 años, 6 meses
Puntos: 0
De acuerdo Respuesta: como guardar un arreglo de checkbox en una bd mysql

solucionado, este es el código que hice.

checkbox.php

Código:
<?php
require_once("conexion.php");
$sql="SELECT * FROM elementos";
$res=mysql_query($sql,$con);
?> 
<html>
<head>
</head>
<body>
<form action="checkbox1.php" method="get">
<table>
<tr>
<td>Cedula<input type="text" name="cedula"></td>
</tr>
<?php
while($reg=mysql_fetch_array($res)){
?>
<tr>
<td>
<input type="checkbox"  value="<?php echo $reg["nombre"] ?>" name="material[]"/>
</td>
<td>
<?php
echo $reg["nombre"];
?>
<br />
<?php
} //cierre while
?>
</td>
<td>
<input type="submit" value="Enviar" name="enviar">
<?php mysql_close($con); ?>
</td>
</tr>
</table>
</form>
</body>
</html>
checkbox1.txt

Código:
<?php
require_once("conexion.php");

#obtiene los valores
echo $_GET["cedula"]."<br>";

#guarda los valores en el vector material
$i=0;
$materiales="";

foreach ($_GET['material'] as $id){
   $material[$i]=$id;
   $materiales="".$material[$i].", ".$materiales."";
   $i++;
}

$sql="INSERT INTO prueba() VALUES(null,'".$_GET['cedula']."','".$materiales."')";
$res=mysql_query($sql,$con);
?>