Ver Mensaje Individual
  #1 (permalink)  
Antiguo 19/11/2013, 14:00
ghiovani_999
 
Fecha de Ingreso: noviembre-2013
Mensajes: 11
Antigüedad: 10 años, 5 meses
Puntos: 0
Pregunta Modificación de multiples registros en un

BUEN DIA GENTE EXPERTA.. ME PUEDEN AYUDAR.....

Bueno lo que deseo en este caso es que se puedan MODIFICAR VARIOS REGISTROS A LA VEZ. Hasta ahora no lo logro hacer. Cuando le doy clic al botón para modificar los datos, no me actualiza ningun registro. ¿qué es lo que estaré haciendo mal?... aqui le dejo el codigo:
Código PHP:
Ver original
  1. //-----------------------------------------------
  2. Actualizar.php
  3.  
  4. <?php
  5. // Connection to the database
  6. $host="localhost"; // Host name
  7. $username="root"; // Mysql username
  8. $password=""; // Mysql password
  9. $db_name="empleados"; // Database name
  10. $tbl_name="empleado1"; // Table name
  11.  
  12.  
  13. // Connect to server and select databse.
  14. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  15. mysql_select_db("$db_name")or die("cannot select DB");
  16.  
  17. $sql="SELECT * FROM $tbl_name";
  18. $result=mysql_query($sql);
  19.  
  20. // Count table rows
  21. $count=mysql_num_rows($result);
  22. ?>
  23. <table width="500" border="0" cellspacing="1" cellpadding="0">
  24. <form name="form1" method="post" action="">
  25. <tr>
  26. <td>
  27. <table width="600" border="0" cellspacing="1" cellpadding="0">
  28.  
  29.  
  30. <tr>
  31. <td align="center"><strong>Id</strong></td>
  32. <td align="center"><strong>Nombre</strong></td>
  33.  
  34. </tr>
  35. <?php
  36. while($rows=mysql_fetch_assoc($result)){
  37. ?>
  38. <tr>
  39. <td align="center"><?php $id[]=$rows['id']; ?><?php echo $rows['id']; ?></td>
  40. <td align="center"><input name="name[]" type="text" id="name" value="<?php echo $rows['nombre']; ?>"></td>
  41.  
  42.  
  43. </tr>
  44. <?php
  45. } ?>
  46.  
  47. <tr>
  48. <td colspan="6" align="center"><input type="submit" name="submit"
  49. value="submit"></td>
  50. </tr>
  51. </table>
  52. </td>
  53. </tr>
  54. </form>
  55. </table>
  56. <?php
  57. // Compruebe si el nombre del botón de "Enviar" está activo, haga lo siguiente
  58. if($submit){
  59. for($i=0;$i<$count;$i++){
  60.  
  61. $sql="UPDATE $tbl_name SET nombre='$name[$i]' WHERE id='$id[$i]'";
  62. $result1=mysql_query($sql);
  63. }
  64. }
  65.  
  66. if($result1){
  67. header("location:asu.php");
  68. }
  69. ?>