Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] PHP OO Modificación de multiples registros en un

Estas en el tema de Modificación de multiples registros en un en el foro de PHP en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 19/11/2013, 14:00
 
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. ?>
  #2 (permalink)  
Antiguo 19/11/2013, 14:13
Avatar de chichote
Colaborador
 
Fecha de Ingreso: diciembre-2004
Ubicación: Santiago - Chile
Mensajes: 1.868
Antigüedad: 19 años, 4 meses
Puntos: 145
Respuesta: Modificación de multiples registros en un

esto está duplicado, te lo conteste en tu otro tema. saludos.
__________________
http://chicho.ninja yiaaaa
  #3 (permalink)  
Antiguo 19/11/2013, 14:17
 
Fecha de Ingreso: noviembre-2013
Mensajes: 11
Antigüedad: 10 años, 5 meses
Puntos: 0
Respuesta: Modificación de multiples registros en un

Hola amigo chichote, enviame el link donde lo has visto plis....
  #4 (permalink)  
Antiguo 19/11/2013, 14:41
Avatar de tquezada  
Fecha de Ingreso: febrero-2013
Ubicación: Santiago
Mensajes: 196
Antigüedad: 11 años, 2 meses
Puntos: 8
Respuesta: Modificación de multiples registros en un

puedes hacer un
Código PHP:
Ver original
  1. echo $sql
en la linea 63 y pruebas en tu bd
supongo que no ingresa nada porque te faltan los puntos y las comillas para concatenar la consulta de la linea 61
Código PHP:
Ver original
  1. $sql="UPDATE $tbl_name SET nombre='".$name[$i]."' WHERE id='".$id[$i]."'";
__________________
¿Sabes cuántos programadores hacen falta para cambiar una bombilla? - no, no ¿Cuántos? - Ninguno... es un problema de hardware.
  #5 (permalink)  
Antiguo 19/11/2013, 14:46
Avatar de gnzsoloyo
Moderador criollo
 
Fecha de Ingreso: noviembre-2007
Ubicación: Actualmente en Buenos Aires (el enemigo ancestral)
Mensajes: 23.324
Antigüedad: 16 años, 4 meses
Puntos: 2658
Respuesta: Modificación de multiples registros en un

Cita:
Iniciado por ghiovani_999 Ver Mensaje
Hola amigo chichote, enviame el link donde lo has visto plis....
Puedes verlo en tu propio perfil, buscando en "Estadisticas" tus propios mensajes...

Y si no te acuerdas tu...
__________________
¿A quién le enseñan sus aciertos?, si yo aprendo de mis errores constantemente...
"El problema es la interfase silla-teclado." (Gillermo Luque)
  #6 (permalink)  
Antiguo 20/11/2013, 14:35
 
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. ?>
  #7 (permalink)  
Antiguo 21/11/2013, 15:52
 
Fecha de Ingreso: noviembre-2013
Mensajes: 11
Antigüedad: 10 años, 5 meses
Puntos: 0
Respuesta: Modificación de multiples registros en un

YA LO SOLUCIONE POR DEDUCCIONES PROPIAS..... POR FIN..
[LE DEJO EL CÓDIGO COMPLETO]
Código PHP:
Ver original
  1. <?php
  2. # FileName="Connection_php_mysql.htm"
  3. # Type="MYSQL"
  4. # HTTP="true"
  5. $hostname_actulizar_sistema = "localhost";
  6. $database_actulizar_sistema = "actualizar";
  7. $username_actulizar_sistema = "root";
  8. $password_actulizar_sistema = "";
  9. $actulizar_sistema = mysql_pconnect($hostname_actulizar_sistema, $username_actulizar_sistema, $password_actulizar_sistema) or trigger_error(mysql_error(),E_USER_ERROR);
  10. ?>
  11. <?php
  12. if (!function_exists("GetSQLValueString")) {
  13. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  14. {
  15. $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  16.  
  17. $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  18.  
  19. switch ($theType) {
  20. case "text":
  21. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  22. break;
  23. case "long":
  24. case "int":
  25. $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  26. break;
  27. case "double":
  28. $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
  29. break;
  30. case "date":
  31. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  32. break;
  33. case "defined":
  34. $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  35. break;
  36. }
  37. return $theValue;
  38. }
  39. }
  40.  
  41. $editFormAction = $_SERVER['PHP_SELF'];
  42. if (isset($_SERVER['QUERY_STRING'])) {
  43. $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  44. }
  45.  
  46. if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  47. $updateSQL = sprintf("UPDATE edicion SET telefono=%s WHERE nombre=%s",
  48. GetSQLValueString($_POST['telefono'], "text"),
  49. GetSQLValueString($_POST['nombre'], "text"));
  50.  
  51.  
  52. mysql_select_db($database_actulizar_sistema, $actulizar_sistema);
  53. $Result1 = mysql_query($updateSQL, $actulizar_sistema) or die(mysql_error());
  54. }
  55.  
  56. mysql_select_db($database_actulizar_sistema, $actulizar_sistema);
  57. $query_mod = "SELECT * FROM edicion ORDER BY nombre ASC";
  58. $mod = mysql_query($query_mod, $actulizar_sistema) or die(mysql_error());
  59. $row_mod = mysql_fetch_assoc($mod);
  60. $totalRows_mod = mysql_num_rows($mod);
  61. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  62. <html xmlns="http://www.w3.org/1999/xhtml">
  63. <head>
  64. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  65. <title>Editar varios</title>
  66. <style type="text/css">
  67. <!--
  68. .Estilo1 {
  69. font-size: 24px;
  70. font-weight: bold;
  71. font-style: italic;
  72. color: #FF0000;
  73. }
  74. -->
  75. </style>
  76. </head>
  77.  
  78. <body>
  79. <p align="center" class="Estilo1">Editar varios Registros</p>
  80. <form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  81. <table border="1" align="center">
  82. <tr align="center">
  83. <td><strong>Nombre y Apellidos</strong></td>
  84. <td><strong>Telfono</strong></td>
  85. </tr>
  86. <?php do { ?>
  87. <tr>
  88. <td><label>
  89. <input name="nombre" type="text" id="nombre" value="<?php echo $row_mod['nombre']; ?>" size="40" />
  90. </label></td>
  91. <td><label>
  92. <input name="telefono" type="text" id="telefono" value="<?php echo $row_mod['telefono']; ?>" size="20" />
  93. </label></td>
  94. </tr>
  95. <?php } while ($row_mod = mysql_fetch_assoc($mod)); ?>
  96. <tr>
  97. <td colspan="2" align="center"><label>
  98. <input type="submit" name="button" id="button" value="Guardar Cambios" />
  99. </label></td>
  100. </tr>
  101. </table>
  102. <input type="hidden" name="MM_update" value="form1" />
  103. </form>
  104. <p>&nbsp; </p>
  105. </body>
  106. </html>
  107. <?php
  108. ?>

Etiquetas: multiples, mysql, registro, registros, select, sql
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 23:32.