Ver Mensaje Individual
  #50 (permalink)  
Antiguo 19/12/2012, 17:02
Avatar de DeivisAndres
DeivisAndres
 
Fecha de Ingreso: febrero-2012
Ubicación: Colombia
Mensajes: 305
Antigüedad: 12 años, 2 meses
Puntos: 41
Respuesta: llenar arreglo con checkbox y caja de texto

Pruebalo asi:

Código PHP:
Ver original
  1. <?php
  2.     //include 'conection.php';
  3.    
  4.     /** conexion ***************************/
  5.      $link = mysql_connect('localhost', 'root', ''); // conectamos a la base de datos
  6.      if(!$link) { // si no se conecta que mande error
  7.         die("Error al intentar conectar: ".mysql_error());
  8.      }
  9.      $db_link = mysql_select_db('prueba', $link); // seleccionamos la base de datos
  10.      if(!$db_link) { // si no selecciona la BD que mande error
  11.         die("Error al intentar seleccionar la base de datos". mysql_error());
  12.      }
  13.      /** fin conexion ************************/
  14.    
  15.     $showsql = mysql_query("SELECT * FROM tema", $link) or die(mysql_error());
  16.            
  17.     if(isset($_REQUEST["ingresar"]) && $_REQUEST["ingresar"] == "Ingresar"){
  18.         if(isset($_REQUEST['norm'])){
  19.             $textos = $_REQUEST['norm'];
  20.             $year = $_REQUEST['year'];
  21.         }          
  22.        
  23.         print_r($textos);
  24.         print_r('<br />');     
  25.         print_r($year);
  26.        
  27.         for ($i=0;$i<count($textos);$i++){
  28.             if($year[$i] == 0){                        
  29.                 unset($year[$i]);
  30.             }
  31.             $year = array_values($year);
  32.             $cedula = "000".$i;                                    
  33.             if((isset($_REQUEST['norm'])) && (isset($_REQUEST['year'])))                    
  34.             {              
  35.                 $insertSQL = mysql_query("INSERT INTO coco (identificacion, id_progsocial, ano) VALUES ('$cedula','".$textos[$i]."','".$year[$i]."')", $link) or die(mysql_error());                           
  36.             }
  37.         }      
  38.     }
  39. ?>
  40. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml2/DTD/xhtml1-strict.dtd">
  41. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  42. <head>
  43. </head>
  44. <body>
  45. <form action="" method="post" name="form1" id="form1">
  46.     <?php
  47.         $a = 0;
  48.         while($Mostrar = mysql_fetch_array($showsql)){ 
  49.     ?>
  50.         <input name="norm[]" type="checkbox" value="<?php echo $Mostrar['Valor']; ?>"><?php echo $Mostrar['Nombre']; ?>
  51.         <input name="year[]" type="text" value="0" /><br />    
  52.     <?php
  53.         ++$a;
  54.         }
  55.     ?> 
  56.     <input id="input" type="submit" name="ingresar" value="Ingresar" />
  57. </form>
  58. </body>
  59. </html>