Foros del Web » Programando para Internet » PHP »

No me actualiza datos

Estas en el tema de No me actualiza datos en el foro de PHP en Foros del Web. Hola, tengo un formulario donde me muestra los datos y si quiero modificar y darle a GUARDAR no me toma los cambios, espero que me ...
  #1 (permalink)  
Antiguo 21/05/2009, 11:28
 
Fecha de Ingreso: mayo-2006
Ubicación: Ciudad de Buenos Aires
Mensajes: 78
Antigüedad: 17 años, 11 meses
Puntos: 2
No me actualiza datos

Hola, tengo un formulario donde me muestra los datos y si quiero modificar y darle a GUARDAR no me toma los cambios, espero que me puedan dar una mano, algo exacto ya que soy novato en php, gracias!!!

Código PHP:
<?
include "conexion.php";
$id $_POST["id"];
$accion $_POST["accion"];
if (!isset(
$accion))
    {
    
$result=mysql_query("SELECT * FROM biblioa WHERE id = $id",$conexion);
    if (
mysql_num_rows($result) == 0
    { echo 
"<b>Identificador Inexistente</b>"; } 
    else 
    {
        
$row=mysql_fetch_row($result);
        echo
"
<table width=100>
<tr>
  <form accion=\"update.php?accion=guardar\" method=\"POST\" type=\"hidden\">
  <b>Ident:</b><br>
  <input type=\"text\" value=\"$row[1]\" name=\"ident\"><br><br>
  <b>Título:</b><br>
  <input type=\"text\" value=\"$row[2]\" name=\"titulo\"><br><br>
  <b>Autor:</b><br>
  <input type=text value=\"$row[3]\" name=\"autor\" size=50><br><br>
  <b>Artículo:</b><br>
  <input type=text value=\"$row[4]\" name=\"articulo\" size=50><br><br>
  <b>Autor del Artículo:</b><br>
  <input type=\"text\" value=\"$row[5]\" name=\"autorart\" size=15><br><br>
  <b>Código:</b><br>
  <input type=\"text\" value=\"$row[6]\" name=\"codigo\" size=15><br><br>
  <b>Editorial:</b><br>
  <input type=\"text\" value=\"$row[7]\" name=\"editorial\" size=15><br><br>
  <b>Año:</b><br>
  <input type=\"text\" value=\"$row[8]\" name=\"anio\" size=30><br><br>
  <b>Observaciones:</b><br>
  <input type=\"text\" value=\"$row[9]\" name=\"observaciones\" size=100><br><br><br>
  <input type=\"hidden\" name=\"id\" value=\"$row[0]\">
  <input type=\"submit\" value=\"Guardar\">
  </form>
  </tr>
  </table>
  </body>
  </html>"
;
}
}
elseif(
$accion == "guardar"){
  
$sql "UPDATE biblioa SET ident='{$_POST['ident']}', titulo='{$_POST['titulo']}', autor='{$_POST['autor']}', articulo='{$_POST['articulo']}', autorart='{$_POST['autorart']}', codigo='{$_POST['codigo']}', editorial='{$_POST['editorial']}', anio='{$_POST['anio']}', observaciones='{$_POST['observaciones']}' WHERE id = '{$_POST['id']}'";
  
$result mysql_query($sql);
  echo
"
  <html>
  <body>
  <b>Los datos han sido actualizados</b>
  </body>
  </html>"
;
}
include 
"cerrar_conexion.php";
?>
  #2 (permalink)  
Antiguo 21/05/2009, 11:33
 
Fecha de Ingreso: diciembre-2007
Mensajes: 131
Antigüedad: 16 años, 4 meses
Puntos: 6
Respuesta: No me actualiza datos

Remplaza

$accion = $_POST["accion"];


por

$accion = $_GET["accion"];



En tu caso, el array $_POST solo tiene los valores de los campos del formulario. La variable 'accion' la estas mandando via URL (via action="") por lo cual su methodo es GET (aunque el formulario este yendo via POST).
  #3 (permalink)  
Antiguo 21/05/2009, 15:36
 
Fecha de Ingreso: mayo-2006
Ubicación: Ciudad de Buenos Aires
Mensajes: 78
Antigüedad: 17 años, 11 meses
Puntos: 2
Respuesta: No me actualiza datos

hola, cambié como me dijiste pero me sigue pasando lo mismo:

Código PHP:
<?
include "conexion.php";
$id $_POST["id"];
$accion $_GET["accion"];
if (!isset(
$accion))
    {
    
$result=mysql_query("SELECT * FROM biblioa WHERE id = $id",$conexion);
    if (
mysql_num_rows($result) == 0
    { echo 
"<b>Identificador Inexistente</b>"; } 
    else 
    {
        
$row=mysql_fetch_row($result);
        echo
"
<table width=100>
<tr>
  <form accion=\"update.php?accion=guardar\" method=\"POST\" type=\"hidden\">
  <b>Ident:</b><br>
  <input type=\"text\" value=\"$row[1]\" name=\"ident\"><br><br>
  <b>Título:</b><br>
  <input type=\"text\" value=\"$row[2]\" name=\"titulo\"><br><br>
  <b>Autor:</b><br>
  <input type=text value=\"$row[3]\" name=\"autor\" size=50><br><br>
  <b>Artículo:</b><br>
  <input type=text value=\"$row[4]\" name=\"articulo\" size=50><br><br>
  <b>Autor del Artículo:</b><br>
  <input type=\"text\" value=\"$row[5]\" name=\"autorart\" size=15><br><br>
  <b>Código:</b><br>
  <input type=\"text\" value=\"$row[6]\" name=\"codigo\" size=15><br><br>
  <b>Editorial:</b><br>
  <input type=\"text\" value=\"$row[7]\" name=\"editorial\" size=15><br><br>
  <b>Año:</b><br>
  <input type=\"text\" value=\"$row[8]\" name=\"anio\" size=30><br><br>
  <b>Observaciones:</b><br>
  <input type=\"text\" value=\"$row[9]\" name=\"observaciones\" size=100><br><br><br>
  <input type=\"hidden\" name=\"id\" value=\"$row[0]\">
  <input type=\"submit\" value=\"Guardar\">
  </form>
  </tr>
  </table>
  </body>
  </html>"
;
}
}
elseif(
$accion == "guardar"){
  
$sql "UPDATE biblioa SET ident='{$_POST['ident']}', titulo='{$_POST['titulo']}', autor='{$_POST['autor']}', articulo='{$_POST['articulo']}', autorart='{$_POST['autorart']}', codigo='{$_POST['codigo']}', editorial='{$_POST['editorial']}', anio='{$_POST['anio']}', observaciones='{$_POST['observaciones']}' WHERE id = '{$_POST['id']}'";
  
$result mysql_query($sql);
  echo
"
  <html>
  <body>
  <b>Los datos han sido actualizados</b>
  </body>
  </html>"
;
}
include 
"cerrar_conexion.php";
?>
la verdad, no sé para q me meto con estas cosas q me cuestan! jajaja

espero ayudita, gracias!
  #4 (permalink)  
Antiguo 21/05/2009, 17:36
 
Fecha de Ingreso: mayo-2006
Ubicación: Ciudad de Buenos Aires
Mensajes: 78
Antigüedad: 17 años, 11 meses
Puntos: 2
Respuesta: No me actualiza datos

Ya lo tengo solucionado, de la siguiente manera:

Código PHP:
<?
include "conexion.php";
$id $_POST["id"];
$accion $_GET["accion"];
if (!isset(
$accion))
    {
    
$result=mysql_query("SELECT * FROM biblioa WHERE id=$id",$conexion);
    if (
mysql_num_rows($result) == 0
    { echo 
"<b>Identificador Inexistente</b>"; } 
    else 
    {
        
$row=mysql_fetch_row($result);
        echo
"
<table width=100>
<tr>
  <form action=\"update.php?accion=guardar\" method=\"POST\">
  <b>ID</b><br>
  <input type=\"text\" value=\"$row[0]\" name=\"id\"><br><br>
  <b>Ident:</b><br>
  <input type=\"text\" value=\"$row[1]\" name=\"ident\"><br><br>
  <b>Título:</b><br>
  <input type=\"text\" value=\"$row[2]\" name=\"titulo\"><br><br>
  <b>Autor:</b><br>
  <input type=text value=\"$row[3]\" name=\"autor\" size=50><br><br>
  <b>Artículo:</b><br>
  <input type=text value=\"$row[4]\" name=\"articulo\" size=50><br><br>
  <b>Autor del Artículo:</b><br>
  <input type=\"text\" value=\"$row[5]\" name=\"autorart\" size=15><br><br>
  <b>Código:</b><br>
  <input type=\"text\" value=\"$row[6]\" name=\"codigo\" size=15><br><br>
  <b>Editorial:</b><br>
  <input type=\"text\" value=\"$row[7]\" name=\"editorial\" size=15><br><br>
  <b>Año:</b><br>
  <input type=\"text\" value=\"$row[8]\" name=\"anio\" size=30><br><br>
  <b>Observaciones:</b><br>
  <input type=\"text\" value=\"$row[9]\" name=\"observaciones\" size=100><br><br><br>
  <input type=\"hidden\" name=\"id\" value=\"$row[0]\">
  <input type=\"submit\" value=\"Guardar\">
  </form>
  </tr>
  </table>
  </body>
  </html>"
;
}
}
elseif(
$accion==guardar){
  
$sql "UPDATE biblioa SET ident='{$_POST['ident']}', titulo='{$_POST['titulo']}', autor='{$_POST['autor']}', articulo='{$_POST['articulo']}', autorart='{$_POST['autorart']}', codigo='{$_POST['codigo']}', editorial='{$_POST['editorial']}', anio='{$_POST['anio']}', observaciones='{$_POST['observaciones']}' WHERE id = '{$_POST['id']}'";
  
$result mysql_query($sql);
  echo
"
  <html>
  <body>
  <b>Los datos han sido actualizados</b>
  </body>
  </html>"
;
}
include 
"cerrar_conexion.php";
?>
le saqué las comillas a elseif($accion==guardar)

muchas gracias!!!
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 07:06.