Ver Mensaje Individual
  #1 (permalink)  
Antiguo 07/09/2012, 14:02
e_daniel316
 
Fecha de Ingreso: marzo-2008
Mensajes: 94
Antigüedad: 17 años
Puntos: 0
mantenimiento:modifica,eliminar

Hola estoy haciendo un formulario sencillo de mantenimiento de registros.Primero tengo una tabla en listado.php selecciono el registro que quiero modificar o eliminar,eso me envia a mantencion.php que es donde realizo las acciones

este es el codigo de mantencion.php:

Código PHP:
<?php include("lib.php");

//si presiona boton "modificar" editamos el registro
if (isset($_POST['modificar'])) {
    
//conectar a mysql
    
$cnx conectar();
    
    
$sql "UPDATE usuario SET";
    
$sql .= "nombre ='".$_POST['nombre']."',";
    
$sql .= "apellido ='".$_POST['apellido']."',";
    
$sql "WHERE rut=".$_POST['rut'];
    
$res mysql_fetch_array($sql) or die (mysql_error());
    
    echo 
"Registro actualizado.<br><a href='listado.php'>Regresar</a>";
    
mysql_close();
    exit;
}

//si presiona boton "eliminar" borramos el registro
if (isset($_POST['eliminar'])) {
    
//conectar a mysql
    
$cnx conectar();
    
    
$sql "DELETE usuario WHERE rut= '$rut' ";
    
$query mysql_query($sql) or die (mysql_error());
    echo 
"Registro borrado.<br><a href='listado.php'>Regresar</a>";
    
mysql_close();
    exit;
}
//si no hay rut no puede seguir
 
if (empty($_GET['rut'])) {
    
header("location:listado.php");
    exit;

//conectar a mysql
$cnx conectar();
//consulta para mostrar datos
$sql "SELECT * FROM  usuario WHERE rut=".$_GET['rut'];
$res mysql_query($sql) or die (mysql_error());

if (
mysql_num_rows($res) >0) {
    
//si hay datos hacemos la otra forma
?>
<form name="form1" method="post" action="<? echo $_SERVER['PHP_SELF'];?>">
<table width="400" border="1" cellpadding="0" cellspacing="0">
<?php
//impresion de datos
while ($fila mysql_fetch_array($res)) {
?>
<tr>
   <td width="150">Rut</td>
   <td><input name="Rut" type="text" readonly="readonly" id="Rut" value="<? echo $fila['rut'];?>"<? echo $fila['rut'];?>"></td>
</tr>
<tr>
   <td>Nombre</td>
   <td><input name="Nombre" type="text" id="Nombre" value="<? echo $fila['nombre'];?>"></td>
</tr>
<tr>
   <td>Apellido</td>
   <td><input name="Apellido" type="text" id="Apellido" value="<? echo $fila['apellido'];?>"></td>
</tr>      
<tr>
   <td>&nbsp;</td>
   <td align="right"><label>
   <input type="submit" name="Submit" value="Modificar">
   </label>
   <input name="eliminar" type="submit" id="eliminar" onclick="javascript:eliminar();" value="Eliminar"></td>
</tr>
</table>
</form>
   <p>
     <?
}
}else {
    
//no hay resultados,rut malo o no existe
    
echo "No se obtuvieron resultados";
    echo 
"<p><a href=listado.php>Volver</p> \n";
}
mysql_close();
?>
</p>
   <p>
     <label></label>
</p>

no puedo hacer ninguna de las dos operaciones, en ambas sale error.

Agradeceria mucho que me ayudaran