Ver Mensaje Individual
  #1 (permalink)  
Antiguo 26/07/2015, 15:47
tavoxd19
 
Fecha de Ingreso: julio-2015
Mensajes: 7
Antigüedad: 8 años, 9 meses
Puntos: 0
Actualizar PHP

Hola quisiera saber si me podria ayudar, necesita actualizar un registro de una bd e intentado pero no me sale. Espero sus respuestas. Gracias

Edita.php


<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<center>
<body>
<form>
<?php
include_once("connect_db.php");
$cod = $_GET['cod'];
$sql = "Select * from alumnos where Codigo = '$cod'";
$tabla = mysql_query($sql) or die(mysql_error());
while ($fila = mysql_fetch_array($tabla)) {
echo "Nombre";
echo $fila["Nombre"] . " | ";
echo "P1: ";
echo $fila["P1"] . " | ";
echo "P2: ";
echo $fila["P2"] . " | ";
echo "P3: ";
echo $fila["P3"] . " | ";
echo "P4: ";
echo $fila["P4"] . "<br /><br />";
// Pasmos el id seleccionado a una sesión y las demás filas = campos.
$_SESSION["cod"] = $cod;
$_SESSION["Nombre"] = $fila["Nombre"];
$_SESSION["P1"] = $fila["P1"];
$_SESSION["P2"] = $fila["P2"];
$_SESSION["P3"] = $fila["P3"];
$_SESSION["P4"] = $fila["P4"];
}
?>
<a href="Alumnos.php" target="_self">Atras</a><br />
<form action="actualizar.php" method="post">
<input type="hidden" name="cod" value="<?php echo $_SESSION['cod']; ?>">
<br />
Nombre:
<br />
<input type="text" name="Nombre" value="<?php echo $_SESSION['Nombre']; ?>"> <br/><br/>
P1:
<br />
<input type="text" name="P1" value="<?php echo $_SESSION['P1']; ?>"> <br/><br/>
P2:
<br />
<input type="text" name="P2" value="<?php echo $_SESSION['P2']; ?>"> <br/><br/>
P3: <br />
<input type="text" name="P3" value="<?php echo $_SESSION['P3']; ?>"> <br/><br/>
P4: <br />
<input type="text" name="P4" value="<?php echo $_SESSION['P4']; ?>"> <br/><br/>
<input type="submit" value="Editar">
</form>




Actualizar.php

<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
include_once("connect_db.php");
// Pasamos los datos del formulario.
$cod= $_POST['cod'];
$nombre = $_POST['Nombre'];
$P1 = $_POST['P1'];
$P2 = $_POST['P2'];
$P3 = $_POST['P3'];
$P4 = $_POST['P4'];
// Pasamos los datos para actualizarlos en la tabla.
$sql = "UPDATE alumnos SET `Nombre`='$nombre',`P1`='$P1',`P2`='$P2',`P3`='$P3 ',`P4`='$P4' WHERE `Codigo`='$cod'";
// Liberamos los datos con la condición if.
if (mysql_query($sql)) {
echo "Actualización exitosa ";
echo "header(location:Alumnos.php)";
} else {
echo "Error de actualizacion ";
}
mysql_close($conexion);
?>
</body>
</html>