Tema: Error UPDATE
Ver Mensaje Individual
  #1 (permalink)  
Antiguo 27/09/2012, 14:59
e_daniel316
 
Fecha de Ingreso: marzo-2008
Mensajes: 94
Antigüedad: 16 años, 1 mes
Puntos: 0
Error UPDATE

Hola estoy recien aprendiendo php con mysql y no me resulta hacer un simple update. Creo que es un error con las variables de las cajas de texto porque al escribir los valores directatemente el la query si me resulta.
aqui dejo el codigo:


Código PHP:
<?php 
require("./lib.php");
$cnx=Conectar();

$rut $_GET['rut'];
$nombre $_POST['nombre'];
$apellido $_POST['apellido'];

if(isset(
$_POST["submit"])){
$sql ="UPDATE usuario SET nombre = '$nombre',apellido = '$apellido' WHERE rut = '$rut'";
$result mysql_query($sql,$cnx);
echo 
"<td>Registro modificado</td>.\n"
echo 
"<td><p><a href='listados2.php'>Volver</p></td>";   
}


//si no hay rut no puede seguir
/*if (empty($_GET['rut'])) {
    header("location:listados2.php");
    exit;
}*/
//conectar a mysql
$cnx conectar();
$rut=$_GET['rut'];
//consulta para mostrar datos
$sql2 "SELECT * FROM  usuario WHERE rut='".$rut."'";
$res mysql_query($sql2) 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" 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"><input type="submit" name="submit" value="Enviar"></td>
</tr>
</table>
</form>
   <?
}
}else {
    
//no hay resultados,rut malo o no existe
    //echo "No se obtuvieron resultados";
}
mysql_close();
?>
por favor ayudenme ,que tengo mal?
gracias