Foros del Web » Programando para Internet » Javascript »

llenado de formulario a partir de una consulta

Estas en el tema de llenado de formulario a partir de una consulta en el foro de Javascript en Foros del Web. Hola foro que tal, pues bueno quisiera si no es mucha molestia si alguien me pudiese explicar con algún ejemplo sencillo como podría realizar el ...
  #1 (permalink)  
Antiguo 01/02/2010, 22:25
Avatar de Lizy94  
Fecha de Ingreso: diciembre-2009
Mensajes: 149
Antigüedad: 14 años, 3 meses
Puntos: 0
llenado de formulario a partir de una consulta

Hola foro que tal, pues bueno quisiera si no es mucha molestia si alguien me pudiese explicar con algún ejemplo sencillo como podría realizar el llenado de un formulario con una consulta, es decir introducir el id de algún registro (en un campo de texto) y de ahi si se encuentra mi registro llenar los demás campos de texto, he estado buscando y se que se realiza cn XML, casi no tengo conocimientos de XML, encontré este ejemplo en la red, pero a mi nada me realiza, si alguien me pudiese decir que podría estar mal con este ejemplo o explicarme con algún otro ejemplo, por favor.
Gracias de antemano a todos

Código PHP:
<html
<
head
<
script language="javascript" type="text/javascript"
function 
nuevoAjax() 
{  
    var 
xmlhttp=false;  
    try  
    {  
        
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");  
    } 
    catch(
e
    {  
        try 
        {  
            
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");  
        }  
        catch(
E) { xmlhttp=false; } 
    } 
    if (!
xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp=new XMLHttpRequest(); }  

    return 
xmlhttp;  


function 
traerDatos() 

    var 
cod=document.form.getElementById("cod").value
    var 
campo1=document.form.getElementById("c1"); 
    var 
campo2=document.form.getElementById("c2"); 
         
    var 
ajax=nuevoAjax(); 
    
ajax.open("POST""ej2.php"true); 
    
ajax.setRequestHeader("Content-Type""application/x-www-form-urlencoded"); 
    
ajax.send("v="+cod); 
             
    
ajax.onreadystatechange=function() 
    { 
        if (
ajax.readyState==4
        { 
            var 
respuesta=ajax.responseXML
            
campo1.value=respuesta.getElementsByTagName("nombre")[0].childNodes[0].data
            
campo2.value=respuesta.getElementsByTagName("apellido")[0].childNodes[0].data
        } 
    } 

</script> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
<title>Ejemplo</title> 
</head> 
<body> 
<form name="form1"  id="form1" method="post" action="">
  <input name="text" type="text" id="cod">
Codigo
<input name="button" type="button" id="b1" onClick="traerDatos();" value="Traer datos">
<br>
<br>
<input name="text2" type="text" id="c1">
Nombre<br>
<br>
<input name="text2" type="text" id="c2">
Apellido</form>
</body> 
</html> 

donde realizo la consulta
Código PHP:
<?php 
$v
=$_POST["v"]; 

$conexion=mysql_connect("localhost""root""elita"); 
mysql_select_db("ejemplo"$conexion); 

$resultado=mysql_query("SELECT nombre, apellido FROM ejemplo WHERE id='$v'")or mysql_error("error!"); 
$registro=mysql_fetch_row($resultado); 

$xml="<?xml version='1.0' encoding='ISO-8859-1'?>"
$xml.="<datos>"
$xml.="<nombre><![CDATA[$registro[0]]]></nombre>"
$xml.="<apellido><![CDATA[$registro[1]]]></apellido>"
$xml.="</datos>"
header("Content-type: text/xml"); 
echo 
$xml
?>
  #2 (permalink)  
Antiguo 01/02/2010, 23:24
Avatar de p3rikl3s  
Fecha de Ingreso: febrero-2009
Ubicación: Valencia
Mensajes: 216
Antigüedad: 15 años, 1 mes
Puntos: 9
Respuesta: llenado de formulario a partir de una consulta

Creo que intentas ahogarte en un vaso de agua. Lo puedes hacer con php, haces la consulta, si la consulta no es vacía creas el formulario en donde cada uno de los campos va contener de forma embebida (en la propiedad value si estuviésemos hablando de un campo de texto por ejemplo) el resultado de tu consulta.

por ejemplo:

Código HTML:
<input id="Nombre" name="nom" type="text" size="32" maxlength="30" value="<?php echo $consulta["nombre"] ?>" /> 
Eso solo un ejemplo - lo que me justifica si tiene algún error de sintaxis y no funciona - pero mi intención era mostrarte una manera lógica de hacerlo embebiendo el resultado con php.

Espero que te sirva de algo y cualquier dudas no demores en consultar.

Saludos.
__________________
También me hago llamar Tropiburguer. Sígueme en twitter: @tropiburguer
  #3 (permalink)  
Antiguo 12/05/2011, 13:07
 
Fecha de Ingreso: enero-2011
Mensajes: 5
Antigüedad: 13 años, 2 meses
Puntos: 1
Respuesta: llenado de formulario a partir de una consulta

Que tal Lizy94 encontraste algo? Tengo un problema muy muy similar lo lograste resolver como te menciono p3rikl3s ?

Gracias necesito de su ayuda
  #4 (permalink)  
Antiguo 30/07/2011, 23:45
 
Fecha de Ingreso: abril-2010
Mensajes: 112
Antigüedad: 13 años, 11 meses
Puntos: 2
Respuesta: llenado de formulario a partir de una consulta

Mira, no se en particular tu ejemplo pero el mio funciona.

Código PHP:
Ver original
  1. &#65279;<html>
  2.  
  3. <head>
  4.  
  5. <script language="javascript" type="text/javascript">
  6.  
  7. function nuevoAjax()
  8.  
  9. {
  10.  
  11.     var xmlhttp=false;
  12.  
  13.     try
  14.  
  15.     {
  16.  
  17.         xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
  18.  
  19.     }
  20.  
  21.     catch(e)
  22.  
  23.     {
  24.  
  25.         try
  26.  
  27.         {
  28.  
  29.             xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  30.  
  31.         }
  32.  
  33.         catch(E) { xmlhttp=false; }
  34.  
  35.     }
  36.  
  37.     if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp=new XMLHttpRequest(); }
  38.  
  39.  
  40.  
  41.     return xmlhttp;
  42.  
  43. }
  44.  
  45.  
  46.  
  47. function traerDatos()
  48.  
  49. {
  50.  
  51.     var cod=document.getElementById("rutCliente").value;
  52.  
  53.     var campo1=document.getElementById("nombreCliente");
  54.  
  55.     var campo2=document.getElementById("apellidoCliente");
  56.  
  57.     var campo3=document.getElementById("direccionCliente");
  58.  
  59.     var campo4=document.getElementById("fonoCliente");
  60.  
  61.     var campo5=document.getElementById("faxCliente");
  62.  
  63.     var campo6=document.getElementById("emailCliente");
  64.  
  65.     var campo7=document.getElementById("notasCliente");
  66.  
  67.     var campo8=document.getElementById("ciudadCliente");
  68.  
  69.     var campo9=document.getElementById("comunaCliente");
  70.  
  71.        
  72.  
  73.     var ajax=nuevoAjax();
  74.  
  75.     ajax.open("POST", "ej2.php", true);
  76.  
  77.     ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  78.  
  79.     ajax.send("v="+cod);
  80.  
  81.            
  82.  
  83.     ajax.onreadystatechange=function()
  84.  
  85.     {
  86.  
  87.         if (ajax.readyState==4)
  88.  
  89.         {
  90.  
  91.             var respuesta=ajax.responseXML;
  92.  
  93.             campo1.value=respuesta.getElementsByTagName("nombre")[0].childNodes[0].data;
  94.  
  95.             campo2.value=respuesta.getElementsByTagName("apellido")[0].childNodes[0].data;
  96.  
  97.             campo3.value=respuesta.getElementsByTagName("direccion")[0].childNodes[0].data;
  98.  
  99.             campo4.value=respuesta.getElementsByTagName("fono")[0].childNodes[0].data;
  100.  
  101.             campo5.value=respuesta.getElementsByTagName("fax")[0].childNodes[0].data;
  102.  
  103.             campo6.value=respuesta.getElementsByTagName("email")[0].childNodes[0].data;
  104.  
  105.             campo7.value=respuesta.getElementsByTagName("notas")[0].childNodes[0].data;
  106.  
  107.             campo8.value=respuesta.getElementsByTagName("ciudad")[0].childNodes[0].data;
  108.  
  109.             campo9.value=respuesta.getElementsByTagName("comuna")[0].childNodes[0].data;
  110.  
  111.         }
  112.  
  113.     }
  114.  
  115. }
  116.  
  117. </script>
  118.  
  119. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  120.  
  121. <title>Ejemplo</title>
  122.  
  123. </head>
  124.  
  125. <body>
  126.  
  127.     <div class="grid_1" id="nombre">Rut:</div>
  128.  
  129.         <input name="rutCliente" id="rutCliente" type="text" size="11" maxlength="11"/> <br /><input type="button" id="b1" value="Traer datos" onClick="traerDatos();"/><br /></div>
  130.  
  131.         <div class="grid_1" id="nombre">Nombre:</div>
  132.  
  133.         <div class="grid_1 prefix_1" id="nombre2">Apellido:</div>
  134.  
  135.         <div class="grid_2" id="campo"><input name="nombreCliente" id="nombreCliente" type="text" size="20"/></div>
  136.  
  137.         <div class="grid_2 prefix_1"id="campo2"><input name="apellidoCliente" id="apellidoCliente" type="text" size="20"/></div>
  138.  
  139.         <div class="grid_2" id="nombre">Direccion:</div>
  140.  
  141.         <div class="grid_4" id="campo"><input id="direccionCliente" name="direccionCliente" type="text" size="47"/></div>
  142.  
  143.         <div class="grid_1 suffix_1" id="nombre">Ciudad:</div><div class="grid_1" id="ciudadcomuna">Comuna:</div>
  144.  
  145.         <div class="grid_2" id="campo">
  146.  
  147.         <input id="ciudadCliente" name="ciudadCliente" type="text" size="20"/></div>
  148.  
  149.         <div class="grid_2" id="campo2"><input id="comunaCliente" name="comunaCliente" type="text" size="20"/></div>
  150.  
  151.         <div class="grid_1" id="nombre">Tel. Fijo:</div> <div class="grid_2 prefix_1" id="nombre2fax">Tel. Móvil:</div>
  152.  
  153.         <div class="clear"></div>
  154.  
  155.         <div class="grid_2" id="campo"><input id="fonoCliente" name="fonoCliente" type="text" size="20"/></div>
  156.  
  157.         <div class="grid_3" id="campo2"><input id="faxCliente" name="faxCliente" type="text" size="20"/></div>
  158.  
  159.         <div class="grid_1" id="nombre">Email:</div>
  160.  
  161.         <div class="grid_4" id="campo"><input id="emailCliente" name="emailCliente" type="text" size="50"/></div>
  162.  
  163.         <div class="grid_1" id="nombre">Notas:</div>
  164.  
  165.         <div class="clear"></div>
  166.  
  167.         <div class="grid_4" id="campo"><textarea id="notasCliente" name="notasCliente" cols="39" rows="2"></textarea></div>
  168.  
  169. </body>
  170.  
  171. </html>

Código PHP:
Ver original
  1. <?php
  2.  
  3. $v=$_POST["v"];
  4.  
  5.  
  6.  
  7. $conexion=mysql_connect("localhost", "user", "pass");
  8.  
  9. mysql_select_db("mulleryc_sav", $conexion);
  10.  
  11.  
  12.  
  13. $resultado=mysql_query("SELECT
  14.  
  15.                         nombre,
  16.  
  17.                         apellido,
  18.  
  19.                         direccion,
  20.  
  21.                         fono,
  22.  
  23.                         fax,
  24.  
  25.                         email,
  26.  
  27.                         notas,
  28.  
  29.                         ciudad,
  30.  
  31.                         comuna
  32.  
  33.                         FROM
  34.  
  35.                         clientes WHERE rut='$v'");
  36.  
  37.                 $registro=mysql_fetch_row($resultado);
  38.  
  39.  
  40.  
  41. $xml="<?xml version='1.0' encoding='ISO-8859-1'?>";
  42.  
  43. $xml.="<datos>";
  44.  
  45. $xml.="<nombre><![CDATA[$registro[0]]]></nombre>";
  46.  
  47. $xml.="<apellido><![CDATA[$registro[1]]]></apellido>";
  48.  
  49. $xml.="<direccion><![CDATA[$registro[2]]]></direccion>";
  50.  
  51. $xml.="<fono><![CDATA[$registro[3]]]></fono>";
  52.  
  53. $xml.="<fax><![CDATA[$registro[4]]]></fax>";
  54.  
  55. $xml.="<email><![CDATA[$registro[5]]]></email>";
  56.  
  57. $xml.="<notas><![CDATA[$registro[6]]]></notas>";
  58.  
  59. $xml.="<ciudad><![CDATA[$registro[7]]]></ciudad>";
  60.  
  61. $xml.="<comuna><![CDATA[$registro[8]]]></comuna>";
  62.  
  63. $xml.="</datos>";
  64.  
  65. header("Content-type: text/xml");
  66.  
  67. echo $xml;
  68.  
  69. ?>
  #5 (permalink)  
Antiguo 21/06/2015, 11:32
Avatar de mari_2015  
Fecha de Ingreso: junio-2015
Mensajes: 2
Antigüedad: 8 años, 9 meses
Puntos: 0
Sonrisa Respuesta: llenado de formulario a partir de una consulta

Cita:
Iniciado por spartmarcus Ver Mensaje
Que tal Lizy94 encontraste algo? Tengo un problema muy muy similar lo lograste resolver como te menciono p3rikl3s ?

Gracias necesito de su ayuda


Buenas, soy nueva y estoy buscando lo mismo que Lizy94 y spartmarcus, tomando el codigo que coloco Ojopex2, lo he modificado un poco por que me arrojaba error, y aunque se que ya es un poco tarde, les dejo aca el codigo por que se que le puede servir a alguien para futuras consultas :

base de datos:mulleryc_sav
codigo:

Código SQL:
Ver original
  1. -- phpMyAdmin SQL Dump
  2. -- version 4.1.12
  3. -- http://www.phpmyadmin.net
  4. --
  5. -- Servidor: 127.0.0.1
  6. -- Tiempo de generación: 21-06-2015 a las 18:18:21
  7. -- Versión del servidor: 5.6.16
  8. -- Versión de PHP: 5.5.11
  9.  
  10. SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
  11. SET time_zone = "+00:00";
  12.  
  13.  
  14. /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
  15. /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
  16. /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
  17. /*!40101 SET NAMES utf8 */;
  18.  
  19. --
  20. -- Base de datos: `mulleryc_sav`
  21. --
  22.  
  23. -- --------------------------------------------------------
  24.  
  25. --
  26. -- Estructura de tabla para la tabla `clientes`
  27. --
  28.  
  29. CREATE TABLE IF NOT EXISTS `clientes` (
  30.   `nombre` VARCHAR(100) COLLATE utf8_spanish_ci DEFAULT NULL,
  31.   `apellido` VARCHAR(100) COLLATE utf8_spanish_ci DEFAULT NULL,
  32.   `direccion` VARCHAR(100) COLLATE utf8_spanish_ci DEFAULT NULL,
  33.   `fono` VARCHAR(100) COLLATE utf8_spanish_ci DEFAULT NULL,
  34.   `fax` VARCHAR(100) COLLATE utf8_spanish_ci DEFAULT NULL,
  35.   `email` VARCHAR(100) COLLATE utf8_spanish_ci DEFAULT NULL,
  36.   `notas` VARCHAR(100) COLLATE utf8_spanish_ci DEFAULT NULL,
  37.   `ciudad` VARCHAR(100) COLLATE utf8_spanish_ci DEFAULT NULL,
  38.   `comuna` VARCHAR(100) COLLATE utf8_spanish_ci DEFAULT NULL
  39. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci;
  40.  
  41. --
  42. -- Volcado de datos para la tabla `clientes`
  43. --
  44.  
  45. INSERT INTO `clientes` (`nombre`, `apellido`, `direccion`, `fono`, `fax`, `email`, `notas`, `ciudad`, `comuna`) VALUES
  46. ('marian', 'alcantara', 'versalles', 'ninguna', 'no', '[email protected]', 'ninguna', 'carupano', 'versalles'),
  47. ('jose', 'gonzales', 'canchunchu', 'ninguna', 'no tiene', '[email protected]', 'ninguna nota hasta ahora', 'caracas', 'santa lucia');
  48.  
  49. /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
  50. /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
  51. /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

archivo php: ej1
codigo:
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. &#65279;<html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Trer Datos con AJAX</title>  
  6. <head>  
  7.     <script language="javascript" type="text/javascript">
  8.     function nuevoAjax(){
  9.         var xmlhttp=false;
  10.        
  11.         try
  12.         {
  13.             xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
  14.         }
  15.      
  16.         catch(e)
  17.         {
  18.             try
  19.             {
  20.                 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  21.             }
  22.            
  23.             catch(E)
  24.             {
  25.                 xmlhttp=false;
  26.             }
  27.         }
  28.      
  29.         if (!xmlhttp && typeof XMLHttpRequest!='undefined')
  30.         {
  31.             xmlhttp=new XMLHttpRequest();
  32.         }
  33.         return xmlhttp;
  34.     }
  35.      
  36.     /*______________________________________________________*/
  37.  
  38.     function traerDatos()  
  39.     {
  40.    
  41.     var form=document.form;
  42.        
  43.     if (form.rutCliente.value==0)
  44.     {
  45.         alert("Debe Ingresar primero el Nombre a buscar");
  46.         form.rutCliente.focus();
  47.         return false;
  48.     }else{
  49.        
  50.             var campo1=document.getElementById("nombreCliente");
  51.             var campo2=document.getElementById("apellidoCliente");
  52.             var campo3=document.getElementById("direccionCliente");
  53.             var campo4=document.getElementById("fonoCliente");
  54.             var campo5=document.getElementById("faxCliente");
  55.             var campo6=document.getElementById("emailCliente");
  56.             var campo7=document.getElementById("notasCliente");
  57.             var campo8=document.getElementById("ciudadCliente");
  58.             var campo9=document.getElementById("comunaCliente");
  59.             var cod=document.getElementById("rutCliente").value;
  60.          
  61.             var ajax=nuevoAjax();
  62.          
  63.             ajax.open("POST", "ej2.php", true);
  64.             ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  65.             ajax.send("v="+cod);
  66.                  
  67.             ajax.onreadystatechange=function()
  68.             {
  69.                 if (ajax.readyState==4)
  70.                 {
  71.                     var respuesta=ajax.responseXML;
  72.          
  73.                     campo1.value=respuesta.getElementsByTagName("nombre")[0].childNodes[0].data;
  74.                     campo2.value=respuesta.getElementsByTagName("apellido")[0].childNodes[0].data;
  75.                     campo3.value=respuesta.getElementsByTagName("direccion")[0].childNodes[0].data;
  76.                     campo4.value=respuesta.getElementsByTagName("fono")[0].childNodes[0].data;
  77.                     campo5.value=respuesta.getElementsByTagName("fax")[0].childNodes[0].data;
  78.                     campo6.value=respuesta.getElementsByTagName("email")[0].childNodes[0].data;
  79.                     campo7.value=respuesta.getElementsByTagName("notas")[0].childNodes[0].data;
  80.                     campo8.value=respuesta.getElementsByTagName("ciudad")[0].childNodes[0].data;
  81.                     campo9.value=respuesta.getElementsByTagName("comuna")[0].childNodes[0].data;
  82.                 }
  83.             }  
  84.         }
  85.     }
  86.     </script>
  87. </head>
  88.      
  89.     <body>
  90.     <center>
  91.         <h3><strong>Trer Datos de Base de Datos sin recargar la pagina con AJAX</strong></h3>
  92.     </center>
  93.    
  94.     <table width="440" height="699" border="0" align="center">
  95.       <tr>
  96.         <td width="430" height="59" align="center" bgcolor="#0099FF">
  97.         <h3>Consulta a Base de Datos en php, html y ajax</h3></td>
  98.       </tr>
  99.      
  100.       <tr>
  101.         <td height="632" bgcolor="#C0C0C0">
  102.         <form method="post" name="form" action="" style="margin-left:2em">    
  103.        
  104.        
  105.         Rut:<input name="rutCliente" id="rutCliente" type="text" size="11" maxlength="11"/>
  106.         <input type="button" id="b1" value="Traer datos" onClick="traerDatos();"/><br /></div><br /><br />
  107.        
  108.        
  109.         <div class="grid_2" id="campo">Nombre: <input disabled name="nombreCliente" id="nombreCliente" type="text" size="20"/></div>        <br />
  110.      
  111.        
  112.         <div class="grid_2 prefix_1"id="campo2">Apellido: <input disabled name="apellidoCliente" id="apellidoCliente" type="text" size="20"/></div><br />
  113.      
  114.        
  115.         <div class="grid_4" id="campo">Email: <input disabled id="emailCliente" name="emailCliente" type="text" size="20"/></div>
  116.         <br />
  117.      
  118.        
  119.         <div class="grid_2" id="campo">Ciudad: <input disabled id="ciudadCliente" name="ciudadCliente" type="text" size="20"/></div>
  120.         <br />
  121.        
  122.         <div class="grid_2" id="campo2">Comuna: <input disabled id="comunaCliente" name="comunaCliente" type="text" size="20"/></div><br />
  123.      
  124.        
  125.         <div class="grid_2" id="campo">Foto: <input disabled id="fonoCliente" name="fonoCliente" type="text" size="20"/></div>
  126.         <br />
  127.        
  128.         <div class="grid_3" id="campo2">Fax: <input disabled id="faxCliente" name="faxCliente" type="text" size="20"/></div>
  129.         <div class="clear"></div>
  130.         <br />
  131.        
  132.         <div class="grid_4" id="campo">Direccion: <input disabled id="direccionCliente" name="direccionCliente" type="text" size="47"/></div><br />
  133.        
  134.        
  135.         Notas:
  136.         <div class="grid_4" id="campo"><textarea disabled style="resize:none" id="notasCliente" name="notasCliente" cols="39" rows="2"></textarea></div>    <br />
  137.            
  138.         <input name="limpiar" value="Limpiar" type="reset" size="20"/>
  139.     </form>
  140.         </td>
  141.       </tr>
  142.     </table>
  143.     </body>  
  144. </html>

Archivo php:ej2
Codigo:
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. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <?php
  5. $v=$_POST["v"];
  6.  
  7.  
  8.  
  9. $conexion=mysql_connect("localhost", "root", "");
  10.  
  11. mysql_select_db("mulleryc_sav", $conexion);
  12.  
  13.  
  14.  
  15. $resultado=mysql_query("SELECT
  16.  
  17.                        nombre,
  18.  
  19.                        apellido,
  20.  
  21.                        direccion,
  22.  
  23.                        fono,
  24.  
  25.                        fax,
  26.  
  27.                        email,
  28.  
  29.                        notas,
  30.  
  31.                        ciudad,
  32.  
  33.                        comuna
  34.  
  35.                        FROM
  36.  
  37.                        clientes WHERE nombre='$v'");
  38.  
  39.                 $registro=mysql_fetch_row($resultado);
  40.  
  41.  
  42.  
  43. $xml="<?php xml version='1.0' encoding='ISO-8859-1'?>";
  44.  
  45. $xml.="<datos>";
  46.  
  47. $xml.="<nombre><![CDATA[$registro[0]]]></nombre>";
  48.  
  49. $xml.="<apellido><![CDATA[$registro[1]]]></apellido>";
  50.  
  51. $xml.="<direccion><![CDATA[$registro[2]]]></direccion>";
  52.  
  53. $xml.="<fono><![CDATA[$registro[3]]]></fono>";
  54.  
  55. $xml.="<fax><![CDATA[$registro[4]]]></fax>";
  56.  
  57. $xml.="<email><![CDATA[$registro[5]]]></email>";
  58.  
  59. $xml.="<notas><![CDATA[$registro[6]]]></notas>";
  60.  
  61. $xml.="<ciudad><![CDATA[$registro[7]]]></ciudad>";
  62.  
  63. $xml.="<comuna><![CDATA[$registro[8]]]></comuna>";
  64.  
  65. $xml.="</datos>";
  66.  
  67. header("Content-type: text/xml");
  68.  
  69. echo $xml;
  70.  
  71. ?>
  72. </html>


Espero que les sirva, suerte...

Última edición por mari_2015; 21/06/2015 a las 12:18 Razón: usuario nuevo, Mejoras

Etiquetas: partir, 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.
Tema Cerrado




La zona horaria es GMT -6. Ahora son las 01:31.