Ver Mensaje Individual
  #2 (permalink)  
Antiguo 23/11/2011, 18:22
rrlower
 
Fecha de Ingreso: febrero-2010
Mensajes: 12
Antigüedad: 15 años
Puntos: 0
Respuesta: problema con checkbox

solucionado adjunto el codigo por si alguien lo necesita

Código PHP:
Ver original
  1. $users = mysqli_query($dbc,"SELECT * FROM clientes");
  2.                            
  3.                             $cant = @mysqli_num_rows($users);
  4.                        
  5.                             while($fila = @mysqli_fetch_array($users)){
  6.                            
  7.                             echo '
  8.                             <form action="editpadmin.php?id='.$fila["id_cliente"].'" method="POST">
  9.                             <table>
  10.                             <tr>
  11.                             <td width="100px" height="26px">
  12.                             '.$fila["id_cliente"].'
  13.                             </td>
  14.                             <td width="180px" height="26px">
  15.                             '.$fila["contacto"].'
  16.                             </td>
  17.                             <td width="120px" height="26px">
  18.                             '.$fila["dnicif"].'
  19.                             </td>
  20.                             <td width="180px" height="26px">
  21.                             <a href="http://'.$fila["website"].'" target="_blank">'.$fila["website"].'</a>
  22.                             </td>
  23.                             <td width="140px" height="26px">
  24.                             ';
  25.                            
  26.                            
  27.                            
  28.                            
  29.                             echo '<input type="checkbox" name="'.$fila["id_cliente"].'" id="'.$fila["id_cliente"].'" ';
  30.                             if ($fila["admin"] == 1)
  31.                             {
  32.                                 echo "checked";
  33.                             }
  34.                            
  35.                             echo ' /><label for="'.$fila["id_cliente"].'"></label>';
  36.                            
  37.                             echo '
  38.                             </td>
  39.                             <td>
  40.                             <button type="submit">Guardar</button>
  41.                             </td>
  42.                             </tr>
  43.                             </form>
  44.                             </table>
  45.                             ';


y este es el codigo para insertar en la base de datos

Código PHP:
Ver original
  1. $id = $_GET['id'];
  2.  
  3. if ($_POST[$id] == "on")
  4. {
  5.     $permisos = 1;
  6. }
  7. else {
  8.     $permisos = 0;
  9. }
  10.  
  11. $p = mysqli_query($dbc,"UPDATE clientes SET admin = '$permisos' WHERE id_cliente =".$id);

saludos