Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/05/2015, 13:20
Avatar de lisllo_1
lisllo_1
 
Fecha de Ingreso: mayo-2015
Mensajes: 12
Antigüedad: 9 años, 9 meses
Puntos: 0
guardar input dinamicos en base de datos

hola buenas a todos tengo un formulario y cuando guardo los datos en la base datos me los guarda todos pero lo del input dinamico me los guarda en blanco
agradezco su ayuda...gracias
Código codigo:
Ver original
  1. <?php
  2.     include_once "../conectar/conexion.php";
  3.     include_once "../inicio.php";
  4.    
  5.     $idS = $_GET['Sede'];
  6.     $idE = $_GET['Escuela'];
  7.     $idN = $_GET['Nombre'];
  8.     $codigoS="";
  9.     $codigoE="";
  10.     $Nombre="";
  11.     $combobit_pn="";
  12.    
  13.     $buscarp = "SELECT MAX(p.Codigo),p.Nombre,e.Nombre AS Escuela,s.Nombre AS Sede FROM programas p,escuelas e,sedes s WHERE p.Nombre = '".$_GET['Nombre']."' AND p.Escuela =".$_GET['Escuela']." AND p.Sede = ".$_GET['Sede']."";
  14.     $resultP = mysql_query($buscarp) or die(mysql_error());
  15.     while($row1=mysql_fetch_row($resultP)){
  16.         $combobit_pn .=$row1[1];
  17.         $combobit_pn1 =$row1[0];
  18.         $codigoE .=$row1[2];
  19.         $codigoS .=$row1[3];
  20.        
  21.     }
  22. ?>
  23. <html lang="es">
  24.     <head>
  25.         <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  26.         <title>Crear Guias</title>
  27.         <link rel="stylesheet" href="/MatrizCensa/estilos/formulario2.css">
  28.         <script language="JavaScript" src="/MatrizCensa/calendario/javascripts.js"></script>
  29.         <link rel="STYLESHEET" type="text/css" href="/MatrizCensa/calendario/estilo.css">
  30.         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  31.         <script type="text/javascript" src="/MatrizCensa/js/jquery-1.3.2.min.js"></script>
  32.         <link rel="stylesheet" href="/MatrizCensa/estilos/estilos.css">
  33.         <script type="text/javascript">
  34.             function crearCampos(cantidad){
  35.                var div = document.getElementById("Guia");
  36.                while(div.firstChild)div.removeChild(div.firstChild); // remover elementos;
  37.                for(var i = 1, cantidad = Number(cantidad); i <= cantidad; i++){
  38.                    var salto = document.createElement("P");
  39.                    var input = document.createElement("input");
  40.                    var text = document.createTextNode("Guia " + i + ": ");
  41.                    input.setAttribute("name", "nombre1[]");
  42.                    input.setAttribute("size", "12");
  43.                    input.className = "input";
  44.                    salto.appendChild(text);
  45.                    salto.appendChild(input);
  46.                    div.appendChild(salto);
  47.                 }
  48.             }  
  49.         </script>
  50.     </head>
  51.      <body>
  52.          <form name = "fcalen" enctype=multipart/form-data" action="" method="post" class="registro" >
  53.          <table>
  54.          <div><tr><td>Sede :<input type="text" name="seden" value ="<?php echo $codigoS; ?>" disabled>
  55.                              <input type="hidden" name="sede" value ="<?php echo $idS; ?>" ></div></td>
  56.          <div><td>Escuela :<input type="text" name="escuelan" value ="<?php echo $codigoE; ?>" disabled>
  57.                             <input type="hidden" name="escuela" value ="<?php echo $idE; ?>" ></div></td></tr>
  58.          <div><tr><td>Programa :<input type="text" name="programan" value ="<?php echo $combobit_pn; ?>" disabled>
  59.                                <input type="hidden" name="programa" value ="<?php echo $combobit_pn1; ?>" ></div></td></tr>
  60.          <tr><td>Numeros de Guias:<input type="text" name="cantidad" id="cantidad" value="" onkeyup="crearCampos(this.value);" ></div></td></tr>
  61.         </table>
  62.           <input type="submit" id="boton" name="crear" value="Crear" onclick="crearCampos(this.form.cantidad.value);" ><div id="Guia"></div>
  63.         </form>
  64.     </body>
  65.     </html>
  66.     <?php
  67.     if(isset($_POST['crear'])){
  68.         for($i = 0; $i < count($_POST['nombre1']); $i++) { // Tomas el valor del campo
  69.         //$variable = $_POST['nombre1'][$i];  // Aqui lo verificas e insertas en la base de datos
  70.        
  71.           $guardar = "INSERT INTO guias(Nombre, Programa, Escuela, Sede, Numero_guia) VALUES ('".($_POST['nombre1'][$i])."','".$_POST['programa']."','".$_POST['escuela']."','".$_POST['sede']."','".$_POST['cantidad']."')";
  72.           $result = mysql_query($guardar) or die(mysql_error());
  73.         }        
  74.           $date = date_default_timezone_get();
  75.           $crearLog = "INSERT INTO log_usr(Usuario, Fecha, Accion) VALUES ('".$_SESSION['userid']."','".$date."','Creacion de guias.')";
  76.           $result = mysql_query($crearLog) or die(mysql_error());      
  77.           /*header("location:/MatrizCensa/");*/
  78.         }elseif(isset($_POST['cancelar'])){
  79.              header("location:/MatrizCensa/inicio.php");
  80.        
  81.     }
  82.  ?>