Foros del Web » Programando para Internet » PHP »

Problema con formulario y recuperación de datos php

Estas en el tema de Problema con formulario y recuperación de datos php en el foro de PHP en Foros del Web. Hola: Primera vez en este foro y también bastante nuevo en lo que es programación php y html. Espero que me puedan resolver esta duda: ...
  #1 (permalink)  
Antiguo 20/06/2010, 20:01
 
Fecha de Ingreso: junio-2010
Mensajes: 3
Antigüedad: 13 años, 10 meses
Puntos: 0
Problema con formulario y recuperación de datos php

Hola:

Primera vez en este foro y también bastante nuevo en lo que es programación php y html. Espero que me puedan resolver esta duda:

Tengo la siguiente página:

Código PHP:
Ver original
  1. <?php
  2.  
  3. include("config.php");
  4.  
  5. error_reporting(E_ALL ^ E_NOTICE);
  6.  
  7.  
  8. $msg = Array();
  9. $error = Array();
  10.  
  11.  
  12. function RecogeDatos()
  13. {
  14.     global $config, $msg, $error;
  15.     $db = @mysql_connect($config['mysql_host'], $config['mysql_user'], $config['mysql_pass']);
  16.     if (!$db) return $error[] = 'Database: '.mysql_error();
  17.     if (!@mysql_select_db($config['mysql_dbname'], $db)) return $error[] = 'Database: '.mysql_error();
  18.     $query = "SELECT * FROM `usuarios` where `rut` = '".mysql_real_escape_string($_POST['rut'])."'";
  19.     $res = mysql_query($query, $db);
  20.     while ($row = mysql_fetch_array($res, MYSQL_ASSOC))
  21.     {
  22.         $nombre = $row["Nombre"];
  23.         $rut = $row["RUT"];
  24.     }
  25.     if (!$res) return $error[] = 'Database: '.mysql_error();
  26.     mysql_free_result($res);
  27.     mysql_close($db);
  28. }
  29. ?>
  30. <html>
  31. <head>
  32.     <title>Sistema de Seguimiento</title>
  33.     <meta http-equiv="Pragma" content="no-cache"/>
  34.     <meta http-equiv="Cache-Control" content="no-cache"/>
  35.     <style type="text/css" media="screen">@import url(style.css);</style>
  36.     <script language="JavaScript" src ="scripts.js"></script>
  37. </head>
  38. <body>
  39.  
  40.     <center>
  41.     <div class="logo1"></div>
  42. <div style="width:500px">
  43.         <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
  44.         <table width="500" border="0" cellspacing="1" cellpadding="3">
  45.             <tr class="head"><th colspan="2">Ingrese el RUT</th></tr>
  46.             <tr>
  47.               <th width="191">Rut: </th>
  48.               <td width="294" align="center"><input type="text" name="rut" size="30" maxlength="100" id="rut" value=""/></td>
  49.             </tr>
  50.             <tr class="head"><th colspan="2">Datos del Usuario</th></tr>
  51.             <tr>
  52.                 <th>Nombre: </th><td align="center"><input name="nombre" type="text" disabled size="30" maxlength="100" value=""/></td>
  53.             </tr>
  54.             <tr>
  55.                 <th>Teléfono 1: </th><td align="center"><input name="telefono1" type="text" disabled size="30" maxlength="100" value=""/></td>
  56.             </tr>
  57.             <tr>
  58.                 <th>Teléfono 2: </th><td align="center"><input name="telefono2" type="text" disabled size="30" maxlength="100" value=""/></td>
  59.             </tr>
  60.             <tr>
  61.                 <th>Teléfono 3: </th>
  62.               <td align="center"><input name="telefono3" type="text" disabled size="30" maxlength="100" value=""/></td>
  63.             </tr>
  64.             <tr>
  65.                 <th>E-mail: </th><td align="center"><input name="email" type="text" disabled size="30" maxlength="100" value=""/></td>
  66.             </tr>
  67.             <tr>
  68.                 <th>Edad: </th><td align="center"><input name="edad" type="text" disabled size="30" maxlength="100"/></td>
  69.             </tr>          
  70.                
  71.                 <th>Sexo:</th><td align="center"><input name="sexo" type="text" disabled size="30" maxlength="100"/></td>
  72.         </table>
  73.         <input type="button" class="button2" value="Inicio" onClick="location.href='index.php';"/>
  74.         <input type="button" class="button2" value="Regresar" onClick="history.go(-1)" />
  75.         <input type="submit" name="botonbuscar" class="button2" value="Buscar"/>
  76.         </form>
  77.     </div>
  78.     </center>
  79.         </div>
  80.         <div style="width:300px"></div>
  81.         <p align="center">&nbsp;</p>
  82. </table>
  83. </body>
  84. </html>

Me gustaría que al obtener la respuesta de la consulta me mostrara el resultado de cada uno de los valores dentro del cuadro de texto definido para tal efecto. ¿Cómo puedo hacer la llamada a la función para que me muestre el contenido dentro de dicho cuadro? (Ej: <input bla bla bla value="<?php $nombre?>">.. Se puede hacer lo que quiero? Lo he intentado de varias maneras sin obtener respuesta....


Desde ya muchas gracias!!!
  #2 (permalink)  
Antiguo 20/06/2010, 20:35
Avatar de bocho0610  
Fecha de Ingreso: enero-2010
Ubicación: <? echo "Santiago, Chile"; ?>
Mensajes: 341
Antigüedad: 14 años, 3 meses
Puntos: 26
Respuesta: Problema con formulario y recuperación de datos php

Código PHP:
Ver original
  1. <?
  2. include('conex.php');
  3. $id=$_POST['id'];
  4. $sql=mysql_query("SELECT * FROM usuario WHERE id=$id",$con);
  5. $row = mysql_fetch_array($sql);
  6.  
  7. $rut=$row['rut'];
  8. $pass=$row['pass'];
  9. $nom=$row['empaque'];
  10. $mail=$row['mail'];
  11. $cat=$row['cat'];
  12.  
  13. ?>
  14. <form name="frmempleado" action="" onsubmit="enviarDatosEmpleado(); return false">
  15. <table>
  16.     <tr><td colspan="2"><input name="id" type="hidden" value="<?echo $id;?>" /></td></tr>
  17.     <tr><td><b>RUT: </b></td><td><input name="rut" type="text" value="<?echo $rut;?>"></td></tr>
  18.     <tr><td><b>PASS: </b></td><td><input name="pass" type="text" value="<?echo $pass;?>"></td></tr>
  19.     <tr><td><b>NOMBRE: </b></td><td><input name="nom" type="text" value="<?echo $nom;?>"></td></tr>
  20.     <tr><td><b>CATEGORIA: </b></td><td><input name="cat" type="text" value="<?echo $cat;?>"></td></tr>
  21.     <tr><td><b>E-MAIL: </b></td><td><input name="mail" type="text" value="<?echo $mail;?>"></td></tr>
  22.     <tr><td colspan="2"><input type="submit" name="Submit" value="Actualizar"></td></tr>
  23. </table>
  24. </form>

SE entiende? si no me hablas.
__________________
Sigueme en Twitter!
Septimoarte.cl <-- Un mundo en cine.
  #3 (permalink)  
Antiguo 20/06/2010, 21:04
 
Fecha de Ingreso: junio-2010
Mensajes: 3
Antigüedad: 13 años, 10 meses
Puntos: 0
Respuesta: Problema con formulario y recuperación de datos php

Quedó así... sin embargo tampoco muestra los valores
Código PHP:
Ver original
  1. <?php
  2.  
  3. include("config.php");
  4.  
  5. error_reporting(E_ALL ^ E_NOTICE);
  6.  
  7.  
  8. $msg = Array();
  9. $error = Array();
  10.  
  11.  
  12. function RecogeDatos()
  13. {
  14.     global $config, $msg, $error;
  15.     $db = @mysql_connect($config['mysql_host'], $config['mysql_user'], $config['mysql_pass']);
  16.     if (!$db) return $error[] = 'Database: '.mysql_error();
  17.     if (!@mysql_select_db($config['mysql_dbname'], $db)) return $error[] = 'Database: '.mysql_error();
  18.     $query = "SELECT * FROM `obesidad` where `rut` = '".mysql_real_escape_string($_POST['rut'])."'";
  19.     $res = mysql_query($query, $db);
  20.     while ($row = mysql_fetch_array($res, MYSQL_ASSOC))
  21.     {
  22.         $nombre = $row["Nombre"];
  23.         $rut = $row["RUT"];
  24.         $telefono1 = $row["Teléfono 1"];
  25.         $telefono2 = $row["Teléfono 2"];
  26.         $telefono3 = $row["Teléfono 3"];
  27.         $email = $row["email"];
  28.         $edad = $row["Edad"];
  29.         $sexo = $row["Sexo"];
  30.     }
  31.     if (!$res) return $error[] = 'Database: '.mysql_error();
  32.     mysql_free_result($res);
  33.     mysql_close($db);
  34. }
  35. ?>
  36. <html>
  37. <head>
  38.     <title>Sistema de Seguimiento</title>
  39.     <meta http-equiv="Pragma" content="no-cache"/>
  40.     <meta http-equiv="Cache-Control" content="no-cache"/>
  41.     <style type="text/css" media="screen">@import url(style.css);</style>
  42.     <script language="JavaScript" src ="scripts.js"></script>
  43. </head>
  44. <body>
  45.  
  46.     <center>
  47.     <div class="logo1"></div>
  48. <div style="width:500px">
  49.         <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
  50.         <table width="500" border="0" cellspacing="1" cellpadding="3">
  51.             <tr class="head"><th colspan="2">Ingrese el RUT</th></tr>
  52.             <tr>
  53.               <th width="191">Rut: </th>
  54.               <td width="294" align="center"><input type="text" name="rut" size="30" maxlength="100" id="rut" value="<?php echo "$rut";?>"/></td>
  55.             </tr>
  56.             <tr class="head"><th colspan="2">Datos del Usuario</th></tr>
  57.             <tr>
  58.                 <th>Nombre: </th><td align="center"><input name="nombre" type="text" disabled size="30" maxlength="100" value="<?php echo RecogeDatos();?>"/></td>
  59.             </tr>
  60.             <tr>
  61.                 <th>Teléfono 1: </th><td align="center"><input name="telefono1" type="text" disabled size="30" maxlength="100" value="<?php echo "$telefono1";?>"/></td>
  62.             </tr>
  63.             <tr>
  64.                 <th>Teléfono 2: </th><td align="center"><input name="telefono2" type="text" disabled size="30" maxlength="100" value="<?php echo "$telefono2";?>"/></td>
  65.             </tr>
  66.             <tr>
  67.                 <th>Teléfono 3: </th>
  68.               <td align="center"><input name="telefono3" type="text" disabled size="30" maxlength="100" value="<?php echo "$telefono3";?>"/></td>
  69.             </tr>
  70.             <tr>
  71.                 <th>E-mail: </th><td align="center"><input name="email" type="text" disabled size="30" maxlength="100" value="<?php echo "$email";?>"/></td>
  72.             </tr>
  73.             <tr>
  74.                 <th>Edad: </th><td align="center"><input name="edad" type="text" disabled size="30" maxlength="100" value="<?php echo "$edad";?>"/></td>
  75.             </tr>          
  76.                
  77.                 <th>Sexo:</th><td align="center"><input name="sexo" type="text" disabled size="30" maxlength="100" value="<?php echo "$sexo";?>"/></td>
  78.         </table>
  79.         <input type="button" class="button2" value="Inicio" onClick="location.href='index.php';"/>
  80.         <input type="button" class="button2" value="Regresar" onClick="history.go(-1)" />
  81.         <input type="submit" name="botonbuscar" class="button2" value="Buscar"/>
  82.         </form>
  83.     </div>
  84.     </center>
  85.         </div>
  86.         <div style="width:300px"></div>
  87.         <p align="center">&nbsp;</p>
  88. </table>
  89. </body>
  90. </html>

Última edición por Soulshifter; 20/06/2010 a las 21:19
  #4 (permalink)  
Antiguo 20/06/2010, 21:10
Avatar de bocho0610  
Fecha de Ingreso: enero-2010
Ubicación: <? echo "Santiago, Chile"; ?>
Mensajes: 341
Antigüedad: 14 años, 3 meses
Puntos: 26
Respuesta: Problema con formulario y recuperación de datos php

aps, bueno ahi no se si tenga algo que ver en la funcion. me imagino que si.

tampoco se si es vital hacerlo con la funcion, si lo haces asi normal resultara como yo lo expuse.
__________________
Sigueme en Twitter!
Septimoarte.cl <-- Un mundo en cine.
  #5 (permalink)  
Antiguo 22/06/2010, 19:41
 
Fecha de Ingreso: junio-2010
Mensajes: 3
Antigüedad: 13 años, 10 meses
Puntos: 0
Respuesta: Problema con formulario y recuperación de datos php

A pesar de todo sigue sin funcionar... alguna idea o al menos algún material de donde pueda leer para solucionar mi problema?


Gracias de nuevo
  #6 (permalink)  
Antiguo 22/06/2010, 20:16
Avatar de carlos_belisario
Colaborador
 
Fecha de Ingreso: abril-2010
Ubicación: Venezuela Maracay Aragua
Mensajes: 3.156
Antigüedad: 14 años
Puntos: 461
Respuesta: Problema con formulario y recuperación de datos php

la funcion debes de llamarla al momento de realizar un evento por ejenplo onkeypress="<?php recogerdtos();?>" xq de la otra manera no la estas llamando

Etiquetas: formulario
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 12:49.