Ver Mensaje Individual
  #1 (permalink)  
Antiguo 24/01/2013, 19:14
tranquilo_8925
 
Fecha de Ingreso: enero-2013
Ubicación: Lima
Mensajes: 38
Antigüedad: 11 años, 3 meses
Puntos: 0
Actualizar Múltiples Registros Php y Mysql

El siguiente código se ha generado con Dreamweaver. 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, sólo me actualiza el último de todos los registros. Cabe indicar que no hay un número exacto de registros, ya que estos se generan mediante una consulta, y se da el caso que en un caso se presenten 15 registros, en otros 20, en otros 10 y asi sucesivamente. Por favor si me pueden ayudar se los agradecería. Quien me pueda ayudar que le agregue el código o modifique si fuera posible.

La tabla se llama EDICION, los campos NOMBRE y TELEFONO (ambos son tipo texto). El que quiero modificar es TELEFONO, porque el campo NOMBRE es la CLAVE PRINCIPAL.

************************************************** *****
<?php require_once('Connections/cNotas.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE edicion SET telefono=%s WHERE nombre=%s",
GetSQLValueString($_POST['telefono'], "text"),
GetSQLValueString($_POST['nombre'], "text"));

mysql_select_db($database_cNotas, $cNotas);
$Result1 = mysql_query($updateSQL, $cNotas) or die(mysql_error());
}

mysql_select_db($database_cNotas, $cNotas);
$query_mod = "SELECT * FROM edicion ORDER BY nombre ASC";
$mod = mysql_query($query_mod, $cNotas) or die(mysql_error());
$row_mod = mysql_fetch_assoc($mod);
$totalRows_mod = mysql_num_rows($mod);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Editar varios</title>
<style type="text/css">
<!--
.Estilo1 {
font-size: 24px;
font-weight: bold;
font-style: italic;
color: #FF0000;
}
-->
</style>
</head>

<body>
<p align="center" class="Estilo1">Editar varios Registros</p>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<table border="1" align="center">
<tr align="center">
<td><strong>Nombre y Apellidos</strong></td>
<td><strong>Teléfono</strong></td>
</tr>
<?php do { ?>
<tr>
<td><label>
<input name="nombre" type="text" id="nombre" value="<?php echo $row_mod['nombre']; ?>" size="40" />
</label></td>
<td><label>
<input name="telefono" type="text" id="telefono" value="<?php echo $row_mod['telefono']; ?>" size="20" />
</label></td>
</tr>
<?php } while ($row_mod = mysql_fetch_assoc($mod)); ?>
<tr>
<td colspan="2" align="center"><label>
<input type="submit" name="button" id="button" value="Guardar Cambios" />
</label></td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1" />
</form>
<p>&nbsp; </p>
</body>
</html>
<?php
mysql_free_result($mod);
?>