Foros del Web » Programando para Internet » PHP »

PHP OO Llenar formulario con llave foranea.

Estas en el tema de Llenar formulario con llave foranea. en el foro de PHP en Foros del Web. Hola tengo 2 formularios de 2 tablas diferentes, el "Formulario 1" de la tabla "escuelas" que tiene una llave primaria "Cct" y el segundo formulario ...
  #1 (permalink)  
Antiguo 13/09/2012, 11:53
 
Fecha de Ingreso: septiembre-2012
Mensajes: 1
Antigüedad: 11 años, 7 meses
Puntos: 0
Pregunta Llenar formulario con llave foranea.

Hola tengo 2 formularios de 2 tablas diferentes, el "Formulario 1" de la tabla "escuelas" que tiene una llave primaria "Cct" y el segundo formulario de la tabla "direcesc" con la llave foranea "Cct".


Formulario 1: "FormEscuelas.php"

Código PHP:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Untitled Document</title>
  6. </head>
  7.  
  8. <body>
  9.  
  10. <form name="FormEscuelas" action="escuelas.php" method="POST">
  11.         <table>
  12.             <tbody>
  13.                 <tr>
  14.                         <td>CCT:</td>
  15.                         <td><input type="text" name="Cct" /></td>
  16.                 </tr>
  17.                 <tr>
  18.                         <td>RFC:</td>
  19.                         <td><input type="text" name="Rfc" /></td>
  20.                 </tr>
  21.                 <tr>
  22.                         <td>Nombre</td>
  23.                     <td><input type="text" name="Nombre" /></td>
  24.                 </tr>
  25.                 <tr>
  26.                         <td>Nombre Corto:</td>
  27.                     <td><input type="text" name="NomCorto" /></td>
  28.                 </tr>
  29.                 <tr>
  30.                         <td>Calle:</td>
  31.                     <td><input type="text" name="Calle" /></td>
  32.                 </tr>
  33.                 <tr>
  34.                         <td>N&uacute;mero:</td>
  35.                     <td><input type="text" name="Numero" /></td>
  36.                 </tr>
  37.                 <tr>
  38.                         <td>Colonia:</td>
  39.                         <td><input type="text" name="Colonia" /></td>
  40.                 </tr>
  41.                 <tr>
  42.                         <td>Estado:</td>
  43.                         <td><input type="text" name="Estado" /></td>
  44.                 </tr>
  45.                 <tr>
  46.                         <td>Ciudad:</td>
  47.                         <td><input type="text" name="Ciudad" /></td>
  48.                 </tr>
  49.                 <tr>
  50.                         <td>Delegaci&oacute;n y Municipio:</td>
  51.                         <td><input type="text" name="Del_Mun" /></td>
  52.                 </tr>
  53.                 <tr>
  54.                         <td>C&oacute;digo Postal:</td>
  55.                         <td><input type="text" name="CodigoPostal" /></td>
  56.                 </tr>
  57.                 <tr>
  58.                         <td>Logo:</td>
  59.                         <td><input type="text" name="Logo" /></td>
  60.                 </tr>
  61.                 <tr>
  62.                         <td>Observaciones:</td>
  63.                         <td><input type="text" name="Obs" /></td>
  64.                 </tr>
  65.                                
  66.                 <tr>
  67.                     <td><br><input type="submit" name= "submit" value="REGISTRAR ESCUELA"></td>
  68.                   <td><br><input type="reset" value="RESET"/></td>
  69.                 </tr>
  70.             </tbody>                       
  71.         </table>
  72.     </form>
  73.  
  74. </body>
  75. </html>


"escuelas.php"

Código PHP:
Ver original
  1. <?php
  2.     include "../conex/conexion.php";
  3.    
  4.         $CCT = $_POST["Cct"];
  5.         $RFC = $_POST["Rfc"];
  6.         $Nombre = $_POST["Nombre"];
  7.         $NombCorto = $_POST["NomCorto"];
  8.         $Calle = $_POST["Calle"];
  9.         $Numero = $_POST["Numero"];
  10.         $Colonia = $_POST["Colonia"];
  11.         $Estado = $_POST["Estado"];
  12.         $Ciudad = $_POST["Ciudad"];
  13.         $Del_Mun = $_POST["Del_Mun"];
  14.         $CodigoPostal = $_POST["CodigoPostal"];
  15.         $Logo = $_POST["Logo"];
  16.         $Obs = $_POST["Obs"];
  17.        
  18.         $query1 = "INSERT INTO escuelas(
  19.             Cct,
  20.             RFC,
  21.             Nombre,
  22.             NombreCorto,
  23.             Calle,
  24.             Numero,
  25.             Colonia,
  26.             Estado,
  27.             Ciudad,
  28.             Del_Mun,
  29.             CodigoPostal,
  30.             Logo,
  31.             Obs)
  32.            
  33.         VALUES(
  34.             '$CCT',
  35.             '$RFC',
  36.             '$Nombre',
  37.             '$NombCorto',
  38.             '$Calle',
  39.             '$Numero',
  40.             '$Colonia',
  41.             '$Estado',
  42.             '$Ciudad',
  43.             '$Del_Mun',
  44.             '$CodigoPostal',
  45.             '$Logo',
  46.             '$Obs
  47.             )";
  48.            
  49.             $result1 = mysql_query($query1,$conexion);
  50.                 if(!$result1){
  51.                     die("Fallo en la Inserci&oacute;n de los Datos".mysql_error());
  52.                     }
  53.                 echo "La escuela se ha registrado satisfactoriamente.";
  54.  
  55. ?>


Formulario 2: "FormDirectEscue.php"

Código PHP:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Untitled Document</title>
  6. </head>
  7.  
  8. <body>
  9.  
  10.     <form name="FormDirectEscue"  action="DirectEscue.php" method="post">
  11.         <table>
  12.             <tbody>
  13.                 <tr>
  14.                     <td>CCT:</td>
  15.                 <td><input type="text" name="Cct"/></td>
  16.                 </tr>
  17.                
  18.                 <tr>
  19.                     <td>Medio:</td>
  20.                     <td><input type="text" name="Medio"/></td>
  21.                 </tr>
  22.                 <tr>
  23.                     <td>Detalle:</td>
  24.                     <td><input type="text" name="Detalle"/></td>
  25.                 </tr>
  26.                 <tr>
  27.                     <td>Asiganado:</td>
  28.                     <td><input type="text" name="Asignado"/></td>
  29.                 </tr>
  30.                 <tr>
  31.                     <td>Observaciones:</td>
  32.                     <td><input type="text" name="Obs"/></td>
  33.                 </tr>
  34.                
  35.                 <tr>
  36.             <td><br><input type="submit" name= "submit" value="Enviar Datos"></td>
  37.             <td><br><input type="reset" value="RESET"/></td>
  38.         </tr>
  39.                                
  40.             </tbody>
  41.         </table>
  42.    
  43.     </form>
  44.  
  45. </body>
  46. </html>

"DirectEscue.php"

Código PHP:
Ver original
  1. <?php
  2.     include "../conex/conexion.php";
  3.    
  4.         $CCT = $_POST["Cct"];
  5.         $Medio = $_POST["Medio"];
  6.         $Detalle = $_POST["Detalle"];
  7.         $Asignado = $_POST["Asignado"];
  8.         $Observaciones = $_POST["Obs"];
  9.        
  10.        
  11.         $query1 = "INSERT INTO direcesc(
  12.                 Medio,
  13.                 Detalle,
  14.                 Asignado,
  15.                 Obs)
  16.                
  17.             VALUES( '$Medio',
  18.                 '$Detalle',
  19.                 '$Asignado',
  20.                 '$Observaciones'
  21.                 )";
  22.                
  23.             $result1 = mysql_query($query1,$conexion);
  24.                 if(!$result1){
  25.                     die("Fallo en la Inserci&oacute;n de los Datos. <br>".mysql_error());
  26.                     }
  27.                 echo "Se ha registrado satisfactoriamente.";   
  28.                
  29.  
  30. ?>


Necesito que en el Text Field de "Cct" de el "Formulario 2", me aparezca el valor de "Cct" de el "Formulario 1", sin que el usuario tenga que teclearlo o modificarlo.

Espero me allá explicado bien y me puedan ayudar gracias.
  #2 (permalink)  
Antiguo 14/09/2012, 04:58
 
Fecha de Ingreso: octubre-2010
Ubicación: España
Mensajes: 1.007
Antigüedad: 13 años, 6 meses
Puntos: 123
Respuesta: Llenar formulario con llave foranea.

utiliza una variable de sesion

$CCT = $_POST["Cct"];
$_SESSION['Cct_form1']=$CCT;

Etiquetas: formulario, html, llave, mysql, sql, tabla, usuarios
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 08:52.