Bien, esto es el código tal y como está ahora:
El formulario de actualización:
edit_account.php:
Código PHP:
//...
<form action="update_account.php?user=<?php echo $_SESSION['nombre']; ?>" method="post" name="update_account">
Nombre de usuario: <?php echo $result[0]; ?><br>
<input type="text" name="user"><br>
Contraseña: <?php echo md5($result[1]); ?><br>
<input type="password" name="pwd"><br>
Nombre: <?php echo $result[2]; ?><br>
<input type="text" name="nombre"><br>
Apellido 1: <?php echo $result[3]; ?><br>
<input type="text" name="apellido1"><br>
Apellido 2: <?php echo $result[4]; ?><br>
<input type="text" name="apellido2"><br>
email: <?php echo $result[5]; ?><br>
<input type="text" name="email"><br>
Teléfono: <?php echo $result[6]; ?><br>
<input type="text" name="telefono"><br>
<input type="submit" value="Actualizar datos">
</form>
//...
y aquí la página de recepción de datos:
update_account.php:
Código PHP:
//...
$result=mysql_fetch_row($sql);
$x=array(0=>'user','pwd','nombre','surname1','surname2','mail','phone');//creo un array cuyos valores son los nombres de los campos del formulario
foreach($x as $post)
{
if(isset($_POST[$post]))
{
$update = 'update usuarios set '.$post.' = "'.$_POST[$post].'" where user = "'.$_SESSION['nombre'].'" and pwd = "'.$_SESSION['pwd'].'";';
$fin = mysql_query($update);
if($fin)
{
echo 'Actualización exitosa<br>';
}
else
{
echo 'Actualización fallida<br>';
}
}
}
//...