Ver Mensaje Individual
  #1 (permalink)  
Antiguo 10/09/2012, 13:10
e_daniel316
 
Fecha de Ingreso: marzo-2008
Mensajes: 94
Antigüedad: 16 años, 1 mes
Puntos: 0
mantencion de registros

Hola, estoy haciendo un formulario de mantenimiento de registro(editar,eliminar),donde anteriomente recibo los datos una pagina llamada listado.php,estos datos me los pone en los campos de texto del form de mantencion.php

este es el codigo:

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

//si la forma ha sido enviada editamos el registro
if (isset($_POST['modificar'])) {
    
//conectar a mysql
    
conectar();
    
    
$sql "UPDATE usuario SET";
    
$sql .= "nombre ='".$_POST['nombre']."',";
    
$sql .= "apellido ='".$_POST['apellido']."',";
    
$sql "WHERE rut=".$_POST['rut'];
    
$query mysql_query($sql) or die (mysql_error());  

    
$res mysql_fetch_array($query) or die (mysql_error());  
    
    echo 
"Registro actualizado.<br><a href='listado.php'>Regresar</a>";
    
mysql_close();
    exit;
}

//si la forma ha sido enviada borramos el registro
if (isset($_POST['eliminar'])) {

    
//conectar a mysql
    
$cnx conectar();
    
    
$sql "DELETE from usuario WHERE rut= '$txtrut'";
    
$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="txtrut" type="text" readonly="readonly" id="txtrut" 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>
nose que tengo de mal que la que presionar cualquiera de los botones(eliminar o modificar) ejecuta todo correctamente pero no borra el registro ni edita el registro, y tampoco entrega ningun error.

Espero que me puedan ayudar.
gracias