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

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