Foros del Web » Programando para Internet » PHP »

Busco un ejemplo de update please

Estas en el tema de Busco un ejemplo de update please en el foro de PHP en Foros del Web. Hace rato he estado buscando un ejemplo de un update en php quiero mandar a llamar los datos de una tabla y me los muestre ...
  #1 (permalink)  
Antiguo 23/11/2009, 14:40
 
Fecha de Ingreso: noviembre-2009
Mensajes: 36
Antigüedad: 14 años, 5 meses
Puntos: 0
Busco un ejemplo de update please

Hace rato he estado buscando un ejemplo
de un update en php
quiero mandar a llamar los datos de una tabla y me los muestre
despues de eso elijo uno y me mande a otra ventana para poder modificarlo
pero la verdad no he encontrado nada de como poder hacerlo helpme
amigos del forosdelweb ayudenme que me reprueban
  #2 (permalink)  
Antiguo 23/11/2009, 14:44
Avatar de JessicaTJ  
Fecha de Ingreso: enero-2007
Ubicación: 127.0.0.1
Mensajes: 472
Antigüedad: 17 años, 3 meses
Puntos: 25
Respuesta: Busco un ejemplo de update please

Código PHP:
$sql "UPDATE users SET
    nombre='"
.$_POST['nombre']."',
    usuario='"
.$_POST['usuario']."',
    password='"
.$_POST['password']."'
    WHERE id='condicion'"

Seria algo asi RendanJes, esto actualizando la BDD desde un formulario POST ^-^
__________________
٩(͡๏̯͡๏)۶ || ٩(͡๏̯͡๏)۶

Última edición por JessicaTJ; 23/11/2009 a las 14:50
  #3 (permalink)  
Antiguo 23/11/2009, 14:52
Avatar de dcreate  
Fecha de Ingreso: octubre-2009
Ubicación: Veracruz
Mensajes: 536
Antigüedad: 14 años, 6 meses
Puntos: 22
Respuesta: Busco un ejemplo de update please

algo asi:

index.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=iso-8859-1" />
  5. <title>Documento sin t&iacute;tulo</title>
  6. <style type="text/css">
  7. <!--
  8. .Estilo1 {
  9.     font-family: Verdana, Arial, Helvetica, sans-serif;
  10.     font-weight: bold;
  11. }
  12. .Estilo2 {
  13.     font-size: 24pt;
  14.     font-weight: bold;
  15.     font-family: Arial, Helvetica, sans-serif;
  16. }
  17. -->
  18. </style>
  19. </head>
  20.  
  21. <body>
  22. <table width="890" border="0" align="center">
  23.   <tr>
  24.     <td>&nbsp;</td>
  25.     <td><div align="center"><span class="Estilo2">BUSCAR CUENTA A MODIFICAR</span></div></td>
  26.     <td>&nbsp;</td>
  27.   </tr>
  28. </table>
  29. <br /><br />
  30. <form id="form1" name="form1" method="post" action="mostrar.php">
  31.   <table width="360" border="1" align="center">
  32.     <tr>
  33.       <td width="167"><div align="right" class="Estilo1">clave </div></td>
  34.       <td width="177"><label>
  35.         <input name="alias" type="text" id="alias" />
  36.       </label></td>
  37.     </tr>
  38.     <tr>
  39.       <td align="right">
  40.         <input type="submit" name="Submit" value="BUSCAR" />
  41.       </td>
  42.       <td><label>
  43.         <input type="button" name="Submit2" value="CANCELAR" onclick="document.location='inicio.php'"/>
  44.       </label></td>
  45.     </tr>
  46.   </table>
  47. </form>
  48.  
  49.  
  50. </body>
  51. </html>

mostrar.php

Código php:
Ver original
  1. <?php
  2. include "conexion.php";
  3. $consecutivo=$_POST['alias'];
  4. conectar();
  5. $bus=mysql_query("select *from tabla where consecutivo='$consecutivo'");
  6. $cons=mysql_fetch_assoc($bus);
  7. ?>
  8.  
  9. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  10. <html xmlns="http://www.w3.org/1999/xhtml">
  11. <head>
  12. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  13. <title></title>
  14. <script>
  15. function validar(formulario)
  16. {
  17. if(formulario.nombre.value=='')
  18. {
  19. alert("LLENAR CAMPOS NECESARIOS\n-NOMBRE");
  20. formulario.nombre.focus();
  21. return false;
  22. }
  23.  
  24. if(formulario.password.value=='')
  25. {
  26. alert("LLENAR CAMPOS NECESARIOS\n-");
  27. formulario.password.focus();
  28. return false;
  29. }
  30. return true;
  31. }
  32. </script>
  33. <style type="text/css">
  34. <!--
  35. .Estilo1 {
  36.     font-size: 24pt;
  37.     font-weight: bold;
  38.     font-family: Arial, Helvetica, sans-serif;
  39. }
  40. .Estilo2 {font-family: Verdana, Arial, Helvetica, sans-serif}
  41. -->
  42. </style>
  43. </head>
  44.  
  45. <body onload="form1.nombre.focus()">
  46. <div align="center"><span class="Estilo1">MODIFICAR DATOS</span></div>
  47. <form onsubmit="return validar(this)" id="form1" name="form1" method="post" action="modificar.php">
  48.   <p>&nbsp;</p>
  49.   <table width="200" border="1" align="center">
  50.     <tr>
  51.       <td><span class="Estilo2"><strong>
  52.         <label>        </label>
  53.       </strong>        
  54.           <label></label>
  55.       </span>        <label><div align="right" class="Estilo2"><strong>NOMBRE:</strong></div>
  56.       </label></td>
  57.       <td><input name="nombre" type="text" id="nombre" style="text-transform:uppercase" value="<?php echo $cons['nombre'];?>" size="50" maxlength="50"/></td>
  58.     </tr>
  59.     <tr>
  60.       <td><div align="right" class="Estilo2"><strong>alias:
  61.       </strong></div>        
  62.         <span class="Estilo2"><strong>
  63.         <label></label>
  64.       </strong></span></td>
  65.       <td><div style="text-transform:uppercase"><?php echo $cons['alias'];?></div><input name="alias" type="hidden" id="alias" style="text-transform:uppercase" value="<?php echo $cons['consecutivo']; ?>" size="30" maxlength="30" /></td>
  66.     </tr>
  67.     <tr>
  68.       <td><div align="right" class="Estilo2"><strong>PASSWORD:
  69.       </strong></div>        
  70.         <span class="Estilo2"><strong>
  71.         <label></label>
  72.       </strong></span></td>
  73.       <td><input name="dato" type="text" id="password" value="<?php echo $cons['dato'];?>" size="30" maxlength="30" /></td>
  74.     </tr>
  75.   </table>
  76.   <p>&nbsp;</p>
  77.   <table width="200" border="0" align="center">
  78.     <tr>
  79.       <td align="right">
  80.         <input type="submit" name="Submit" value="ACTUALIZAR" />
  81.       </td>
  82.       <td><label>
  83.         <input type="button" name="Submit2" value="CANCELAR" onclick="document.location='inicio.php'"/>
  84.       </label></td>
  85.     </tr>
  86.   </table>
  87.   <p>&nbsp;</p>
  88. </form>
  89. </body>
  90. </html>

modificar.php

Código php:
Ver original
  1. <?php
  2. include "conexion.php";
  3. $id=$_POST['alias'];
  4. $nombre=$_POST['nombre'];
  5. $dato=$_POST['dato'];
  6. conectar();
  7. mysql_query("UPDATE password SET nombre='$nombre',dato='$dato' WHERE consecutivo='$id'");
  8. echo '<script>alert("DATOS ACTUALIZADOS CON EXITO");</script>';
  9. echo '<script>document.location="otra_pag.php";</script>';
  10. ?>

conexion.php
Código php:
Ver original
  1. <?php
  2. function conectar()
  3. {
  4.     mysql_connect("localhost","usuario","password");
  5.     mysql_select_db("base_de_datos");
  6. }
  7. function desconectar()
  8. {
  9.     mysql_close();
  10. }
  11. ?>

solo adecualo alos tu base de datos, espero te ayude, suerte
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 20:31.