Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/05/2017, 15:38
saulrayados
 
Fecha de Ingreso: abril-2016
Mensajes: 44
Antigüedad: 8 años
Puntos: 0
Pregunta como hacer que al dar clic en guardar se actualice la información

como puedo hacer para que al dar clic en guardar cambios se actualice la información en la base de datos?
el código es el siguiente

Código HTML:
Ver original
  1. <meta charset="utf-8">
  2. <style type="text/css">
  3. p.simulaLink {color: blue; cursor:pointer;}
  4.  
  5. <script type="text/javascript">
  6.  
  7. function transformarEnEditable(nodo) {
  8. var nodoContent = nodo.querySelectorAll("p");
  9. var claveInicial = nodoContent[0].firstChild.nodeValue;
  10. var nombreInicial = nodoContent[1].firstChild.nodeValue;
  11. var especialidadInicial = nodoContent[2].firstChild.nodeValue;
  12. var consultorioInicial = nodoContent[3].firstChild.nodeValue;
  13. var unidadInicial = nodoContent[4].firstChild.nodeValue;
  14. var cedulaInicial = nodoContent[5].firstChild.nodeValue;
  15.  
  16. var nuevoCodigo = '<tr>'+
  17. '<td> <input type="text" name="id" id="id" value="'+claveInicial+'" size="10"></td>'+
  18. '<td> <input type="text" name="titulo" id="titulo" value="'+nombreInicial+'" size="10"></td>'+
  19. '<td> <input type="text" name="texto" id="texto" value="'+especialidadInicial+'" size="20"></td>'+
  20. '<td> <input type="text" name="categoria" id="categoria" value="'+consultorioInicial+'" size="10"></td>'+
  21. '<td> <input type="text" name="fecha" id="fecha" value="'+unidadInicial+'" size="10"></td>'+
  22. '<td> <input type="text" name="imagen" id="imagen" value="'+cedulaInicial+'" size="10"></td>'+
  23. '<td> <p class="simulaLink">Guardar cambios</p>'+
  24. '<p>Borrar</p></td>'+
  25. '</tr>';
  26.  
  27. nodo.innerHTML = nuevoCodigo;
  28. }
  29.  
  30.  
  31. </head>
  32.  
  33.  
  34. <table border="1" cellpadding="0" cellspacing="0">
  35. <tr>
  36. <td><p><b>Clave</b></p></td>
  37. <td><p><b>Nombre</b></p></td>
  38. <td><p><b>Especialidad</b></p></td>
  39. <td><p><b>Consultorio</b></p></td>
  40. <td><p><b>Unidad Médica</b></p></td>
  41. <td><p><b>Cedula Profesional</b></p></td>
  42. <td> </td>
  43. </tr>
  44.  
  45. <tr>
  46. <td><p><?php echo $row['doc_cve']; ?></p></td>
  47. <td><p><?php echo $row['doc_nombre']; ?></p></td>
  48. <td><p><?php echo $row['doc_especialidad']; ?></p></td>
  49. <td><p><?php echo $row['doc_consultorio']; ?></p></td>
  50. <td><p><?php echo $row['doc_unidadmedica']; ?></p></td>
  51. <td><p><?php echo $row['doc_ced_prof']; ?></p></td>
  52. <td><p class = "simulaLink" onclick="transformarEnEditable(this.parentNode.parentNode)">Editar</p>
  53.  
  54. <p>Borrar</p></td>
  55. </tr>
  56. <?php } ?>
  57.  
  58. </body>
  59. </html>

Código PHP:
Ver original
  1. <?php
  2.     $conexion = new PDO('mysql:host=localhost;dbname=hospital', 'root', '');
  3.  
  4.     $sql = 'SELECT * FROM doctores';
  5.     $result = $conexion->query($sql);
  6.     $rows = $result->fetchAll();
  7. ?>
  8.         <?php
  9.             foreach ($rows as $row) {  
  10.         ?>

Última edición por saulrayados; 16/05/2017 a las 19:35