Ver Mensaje Individual
  #1 (permalink)  
Antiguo 02/05/2012, 17:02
echo_
 
Fecha de Ingreso: noviembre-2011
Ubicación: Paris
Mensajes: 450
Antigüedad: 12 años, 5 meses
Puntos: 7
problema con formulario

Buenos dias a todos en el foro, lo que pasa es lo siguiente no puedo actualizar los datos de mi base mi codigo es el siguiente espero y me puedan ayudar.
Saludos!

guardar
Código PHP:
<?php
include 'conexion.php';
if (!isset(
$_GET['accion'])){
        echo
"
        <html>
        <head><title>Guardar datos en la base</title></head>
        <body>
<h3>Guardar datos en la base</h3>
<form name=\"form1\" method=\"post\"action=\"guardar.php?accion=guardar\">
  <p>nombre:<br>
    <input type=\"text\" name=\"nombre\">
  </p>
<p>apellido:<br>
    <input type=\"text\" name=\"apellido\">
  </p>
<p>dni:<br>
    <input type=\"text\" name=\"dni\">
  </p>

  <p>
    <input type=\"submit\" name=\"Submit\" value=\"Guardar Datos\">
  </p>
</form>
</body>
</html>"
;
}elseif(
$_GET['accion']=='guardar'){


  include
'conexion.php';
mysql_query("insert into usuarios(nombre,apellido,dni) values ('$_POST[nombre]','$_POST[apellido]','$_POST[dni]')",
     
$conexion) or die("Problemas en el select".mysql_error());
         
mysql_close($conexion);
  echo
' <html>
    <head></head>
    <body>
    <h3>Los datos han sido guardados</h3>
    '
.$_POST['dni'].'
    '
.$_POST['nombre'].'
    '
.$_POST['apellido'].'
    </body>
    </html>'
;
}

?>

mostrar
Código PHP:
<?php
include "conexion.php";
$result=mysql_query("SELECT * FROM usuarios ORDER BY nombre",
  
$conexion);
echo
"<table width=300>
<tr>
<td><b>Nombre</b></td><td><b>Apellido</b></td><td><b>DNI</b></td>
</tr>"
;
while(
$row=mysql_fetch_row($result)){
  echo
"<tr>
    <td>$row[1]</td><td>$row[2]</td><td>$row[3]
      <a href='actualizar.php?id=$row[0]'>Actualizar</a></td>
    </tr>"
;
}
echo
"</table>";
include 
"cerrar_conexion.php";
?>

actualizar
Código PHP:
<?php
include "conexion.php";

if (!isset(
$_GET['accion'])){
  
$result=mysql_query("SELECT * FROM usuarios WHERE id=$id",
    
$conexion);
  
$row=mysql_fetch_row($result);
  echo
'<html>
  <head><title>Actualizar datos de la base</title></head>
  <body>
  <form action="actualizar.php?accion=guardar" method="POST">
  Nombre:<br>
  <input type="text" value='
.$row[1].' name="nombre"><br>
  Apellido:<br>
  <input type="text" value='
.$row[2].' name="apellido"><br>
  DNI:<br>
  <input type="text" value='
.$row[3].' name="dni"><br>
  <input type="hidden" name="id" value="$row[0]">
  <input type="submit" value="Guardar">
  </form>
  </body>
  </html>'
;
}elseif(
$_GET['accion']=='guardar'){
  
$result=mysql_query("UPDATE usuarios SET nombre='$_POST[nombre]',
    apellido='$_POST[apellido]', dni='$_POST[dni]' WHERE id = '$id'"
,$conexion);
    

    
  echo
"
  <html>
  <body>
  <h3>Los registros han sido actualizados</h3>
  </body>
  </html>"
;
}
include 
"cerrar_conexion.php";
?>