Ver Mensaje Individual
  #1 (permalink)  
Antiguo 22/01/2012, 14:58
inthedark
 
Fecha de Ingreso: enero-2012
Ubicación: Jaen
Mensajes: 5
Antigüedad: 12 años, 3 meses
Puntos: 0
Pregunta Update mysql php formulario

Buenas.
Estoy haciendo un formulario en php que coga información de una base de datos desde phpmyadmin.
Tengo un boton de borrar y otro de modificar.
Me falla el de modificar soy nuevo en esto.
Y el boton deberia de leer los datos de esa linea, introducierlo en el formulario y desde hay ya editar.
La id es el DNI.

Es un mismo fichero para simplificar lo cuelgo por si alguna persona puede echarme un cable.Thanks. [ginyo]
Es el if ($_GET['editar']) y no se si el : <a href='rafa.php?editar=$row[Nombre].$row[Apellido].$row[Direccion].$row[DNI]'>Editar</a>";
debe de coger todos los campos o que.

<?php
//usuario root y contraseña rafa
$link = mysql_connect('localhost', 'root');
//$link = mysql_connect('localhost', 'root' , 'rafa');
if (!$link) {
die('Not connected : ' . mysql_error());

}

// Seleccionar rafa como base de datos activa
$db_selected = mysql_select_db('rafa', $link);
if (!$db_selected) {
die ('Can\'t use rafa : ' . mysql_error());
}
//insertar valores en la tabla llamada tabla con el boton aceptar llamado nuevo
if ($_GET['Nuevo'])
{
$query = "insert into tabla values ('".$_GET['Nombre']."','".$_GET['Apellido']."','".$_GET['Direccion']."','".$_GET['DNI']."')";
$result = mysql_query($query);

}
//eliminar alumno cogiendo la clave primaria DNI
if ($_GET['eliminar'])
{
$query = "delete from tabla where DNI = '$_GET[eliminar]'";
$result = mysql_query($query);

}
//editar alumno cogiendo todos los campos
if ($_GET['editar'])
{
$Nombre = $_GET["Nombre"];
$Apellido= $_GET["Apellido"];
$Direccion= $_GET["Direccion"];
$DNI= $_GET["DNI"];


mysql_query("UPDATE 'blog' SET 'titulo' = [$titulo] WHERE titulo='".$_GET["titulo"]."'");

$query = "update from tabla where Nombre = ('".$_GET['Nombre']."','".$_GET['Apellido']."','".$_GET['$Direccion']."',".$_GET['DNI'].")";
$result = mysql_query($query);
echo "actualizado correctamente";
}


?>
<html><head><title>Alumnos 2012</title></head>
<body>
<h1><u>Matriculacion de Alumnos 2012</u></h1>

<form action="rafa.php" method="get">
<fieldset>

Nombre : <input type=text name="Nombre" maxlength=13 size=13 value="<?php echo $row['Nombre'];?>"><br><br>

Apellido : <input type=text name="Apellido" maxlength=30 size=30 value="<?php echo $row['Apellido'];?>"><br><br>

Direccion : <input type=text name="Direccion" maxlength=60 size=30 value="<?php echo $row['Direccion'];?>"><br><br>

DNI : <input type=text name="DNI" maxlength=9 size=9 value="<?php echo $row['DNI'];?>"><br><br>

</fieldset>
</form>
<h1><u>Alumnos Matriculados</u></h1>
<?php

$query = "SELECT * FROM tabla";

$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result))
{
echo $row['Nombre']. " - ". $row['Apellido']. " - ". $row['Direccion']. " - ". $row['DNI'].
"<a href='rafa.php?eliminar=$row[DNI]'>Borrar</a>
". " "."
<a href='rafa.php?editar=$row[Nombre].$row[Apellido].$row[Direccion].$row[DNI]'>Editar</a>";
echo "<br />";
}
//formulario html con los campos
?>
</body>
</html>