Foros del Web » Programando para Internet » PHP »

Problema UPDATE y PHP (Misterioso error)

Estas en el tema de Problema UPDATE y PHP (Misterioso error) en el foro de PHP en Foros del Web. hola tengo un problema muy raro: tengo un formulario donde muestro los datos actuales de la base de datos , para que el usuario los ...
  #1 (permalink)  
Antiguo 24/01/2010, 10:06
 
Fecha de Ingreso: mayo-2009
Mensajes: 147
Antigüedad: 15 años
Puntos: 1
Pregunta Problema UPDATE y PHP (Misterioso error)

hola tengo un problema muy raro:
tengo un formulario donde muestro los datos actuales de la base de datos , para que el usuario los actualice a su gusto, por ejemplo:


Código PHP:
<form action="editaroficiales.php" method="post">    
<?php
$username
=$_SESSION['s_username'];

 
$resultado2 = @mysql_query ("SELECT * FROM clanprueba WHERE `username` = '$username' ");
    while (
$fila mysql_fetch_array($resultado2))
    {
     
?>

<input name="red1" type="text" value="<? echo $fila['red1']; ?>"><br />

<input name="" type="submit" value="Enviar">
</form>

eL CODIGO PHP ES EL SIG:

Código PHP:
$red1=$_POST['red1'];
$sql="UPDATE clanprueba SET red1 = '$red1' WHERE username = '$username'";
mysql_query($sql);



//MUESTRO LOS DATOS
$resultado2 = @mysql_query ("SELECT * FROM clanprueba WHERE `username` = '$username'");

            
 while (
$fila mysql_fetch_array($resultado2)) {
echo 
$fila['red1'];

eL PROBLEMA ES QUE LOS DATOS DE LA BASE SE BORRAN Y QUEDA EL CAMPO EN BLANCO, CUANDO HAGO UN ECHO DE LOS DATOS DEL FORM PARA VER SI LAS VARIABLES SON ENVIADAS POR POST, FUNCIONA PERFECTAMENTE, EN DONDE DICE "MUESTRO LOS DATOS" ES DONDE INMEDIATAMENTE DESPUES DE HACER CLICK EN EL BOTON DEL FORMULARIO (YA HABIENDO INGRESADO LOS DATOS NUEVOS), SE MUESTRAN LOS DATOS QUE SUPUESTAMENTE SE ACTUALIZARON, PERO CUANDO VOY A LA BASE EL CAMPO ESTÁ EN BLANCO... ESTIO ES MUY RARO YA QUE ME MUESTRA LIOS DATOS ACTUALIZADOS COMO SI SE HUBIERAN GUARDADO EN LA BASE PERO EN REALIDAD NO HAY NADA, EL CAMPO ESTÁ EN BLANCO...

COMO PUEDE SER QUE ME MUESTRE DATOS DE LA BASE SI NO EXISTEN??????


SI ENVÉS DE PONER UNA VARIABLE PONGO UN TEXTO CUAQUIERA SI FUNCIONA, ES DECIR QUE SE ACTUALIZAN LOS DATOS PERFECTAMENTE EJEMPLO:

Código PHP:
$sql="UPDATE clanprueba SET red1 = 'TEXTO CUALQUIERA' WHERE username = '$username'";
mysql_query($sql); 

OSEA QUE EL PROBLEMA PUEDE ESTAR EN LA VARIABLE, ES LO UNICO QUE PUDE DESCUBRIR, LO DEMÁS ES UN MISTERIO DE LA NATURALEZA... XD

BUENO DESDE YA GRACIAS POR SU AYUDA
  #2 (permalink)  
Antiguo 24/01/2010, 10:26
 
Fecha de Ingreso: enero-2010
Mensajes: 36
Antigüedad: 14 años, 3 meses
Puntos: 0
Respuesta: Problema UPDATE y PHP (Misterioso error)

hacete un:
echo $sql;
antes de la linea mysql_query($sql);
para ver que query se está ejecutando.
  #3 (permalink)  
Antiguo 24/01/2010, 10:31
 
Fecha de Ingreso: mayo-2009
Mensajes: 147
Antigüedad: 15 años
Puntos: 1
Respuesta: Problema UPDATE y PHP (Misterioso error)

Cita:
Iniciado por Gaboto83 Ver Mensaje
hacete un:
echo $sql;
antes de la linea mysql_query($sql);
para ver que query se está ejecutando.

LO HICE Y EFECTIVAMENTE SE ESTÁ EJECUTANDO...

Código PHP:
UPDATE clanprueba SET red1 'DATO' WHERE username 'trombonete' 
  #4 (permalink)  
Antiguo 24/01/2010, 10:34
 
Fecha de Ingreso: enero-2010
Mensajes: 36
Antigüedad: 14 años, 3 meses
Puntos: 0
Respuesta: Problema UPDATE y PHP (Misterioso error)

que tipo de campo es red1 ?
  #5 (permalink)  
Antiguo 24/01/2010, 10:40
 
Fecha de Ingreso: mayo-2009
Mensajes: 147
Antigüedad: 15 años
Puntos: 1
Respuesta: Problema UPDATE y PHP (Misterioso error)

Cita:
Iniciado por Gaboto83 Ver Mensaje
que tipo de campo es red1 ?
`red1` varchar(30) default NULL,
  #6 (permalink)  
Antiguo 24/01/2010, 10:52
 
Fecha de Ingreso: noviembre-2004
Ubicación: NULL
Mensajes: 652
Antigüedad: 19 años, 5 meses
Puntos: 6
Respuesta: Problema UPDATE y PHP (Misterioso error)

Prueba asi


Código PHP:


<?
if (isset($_POST['action']) && $_POST['action'] == 'edit')
{
    
$red1 = (int)$_POST['red1'];
    
$sql="UPDATE clanprueba SET red1 ='$red1' WHERE username = '$username'"
    
mysql_query($sql); 

}

//MUESTRO LOS DATOS 
$resultado2 = @mysql_query ("SELECT * FROM clanprueba WHERE `username` = '$username'"); 

while (
$fila mysql_fetch_array($resultado2)) { 
echo 
$fila['red1']; 
}  

?>
<form action="editaroficiales.php" method="post">     
<?php 
$username
=$_SESSION['s_username']; 

 
$resultado2 = @mysql_query ("SELECT * FROM clanprueba WHERE `username` = '$username' "); 
    while (
$fila mysql_fetch_array($resultado2)) 
    { 
     
?> 

<input name="red1" type="text" value="<? echo $fila['red1']; ?>"><br /> 
<input type="hidden" name="action" value="edit">
<input name="submit" type="submit" value="Enviar"> 
</form>
Fijate en el campo del formulario:
<input type="hidden" name="action" value="edit">

copia el codigo y prueba y me avisas como te va
  #7 (permalink)  
Antiguo 24/01/2010, 10:59
Avatar de bioxido  
Fecha de Ingreso: diciembre-2008
Ubicación: $_SERVER['PHP_SELF']
Mensajes: 601
Antigüedad: 15 años, 5 meses
Puntos: 21
Respuesta: Problema UPDATE y PHP (Misterioso error)

si decis que con un SELECT te muestra los datos, entonces es porque los datos estan....

Estas seguro que con el usuario que te logeas despues a la DB tenes todos los permisos para visualizar tablas,etc?
  #8 (permalink)  
Antiguo 24/01/2010, 11:05
 
Fecha de Ingreso: mayo-2009
Mensajes: 147
Antigüedad: 15 años
Puntos: 1
Respuesta: Problema UPDATE y PHP (Misterioso error)

pilucho hice lo que me dijiste y el resultado es un cero. se guarda en numero 0 en el campo


bioxido si estoy seguro
  #9 (permalink)  
Antiguo 24/01/2010, 11:43
 
Fecha de Ingreso: mayo-2009
Mensajes: 147
Antigüedad: 15 años
Puntos: 1
Respuesta: Problema UPDATE y PHP (Misterioso error)

El problema persiste, que puedoo hacer?
  #10 (permalink)  
Antiguo 24/01/2010, 11:53
 
Fecha de Ingreso: noviembre-2004
Ubicación: NULL
Mensajes: 652
Antigüedad: 19 años, 5 meses
Puntos: 6
Respuesta: Problema UPDATE y PHP (Misterioso error)

Código PHP:
Cambia esto:
if (isset(
$_POST['action']) && $_POST['action'] == 'edit'

    
$red1 = (int)$_POST['red1']; 
    
$sql="UPDATE clanprueba SET red1 ='$red1' WHERE username = '$username'";  
    
mysql_query($sql);  



Por esto:

    if (isset(
$_POST['action']) && $_POST['action'] == 'edit'

    
$red1 $_POST['red1'];  
    
$sql="UPDATE clanprueba SET red1 ='$red1' WHERE username = '$username'";  
    
mysql_query($sql);  




Cita:
Iniciado por trombonete Ver Mensaje
pilucho hice lo que me dijiste y el resultado es un cero. se guarda en numero 0 en el campo


bioxido si estoy seguro
Hola tienes mas datos en tu tabla?? en via el codigo completo si envia un "0" vamos por buen camino el problema esta en el GET veamos tu codigo postealo aqui y lo solucionamos

Última edición por pilucho; 24/01/2010 a las 11:59
  #11 (permalink)  
Antiguo 24/01/2010, 12:32
 
Fecha de Ingreso: mayo-2009
Mensajes: 147
Antigüedad: 15 años
Puntos: 1
Respuesta: Problema UPDATE y PHP (Misterioso error)

acabo de encontrar el error pero no se por que pasa,.
Cuando le pongo al codigo un else (por si el usuario no inició sesion) y hago un
y luego instancio una clase


Código PHP:
require ("clases.php");
  
$clase_clases = new Clases();  
  
$clase_clases->estilos();
  
$clase_clases->LOGO_Cabecara();
  
$clase_clases->Botonera();
<
table width="100%" border="0" cellspacing="0" cellpadding="0">
  <
tr>
    <
td>Tu no iniciaste sesion</td>
  </
tr>
</
table

Ahí es donde se produce el error, ahora... por que? no tengo la menor idea ...
  #12 (permalink)  
Antiguo 24/01/2010, 12:50
 
Fecha de Ingreso: noviembre-2004
Ubicación: NULL
Mensajes: 652
Antigüedad: 19 años, 5 meses
Puntos: 6
Respuesta: Problema UPDATE y PHP (Misterioso error)

Cita:
Iniciado por trombonete Ver Mensaje
acabo de encontrar el error pero no se por que pasa,.
Cuando le pongo al codigo un else (por si el usuario no inició sesion) y hago un
y luego instancio una clase


Código PHP:
require ("clases.php");
  
$clase_clases = new Clases();  
  
$clase_clases->estilos();
  
$clase_clases->LOGO_Cabecara();
  
$clase_clases->Botonera();
<
table width="100%" border="0" cellspacing="0" cellpadding="0">
  <
tr>
    <
td>Tu no iniciaste sesion</td>
  </
tr>
</
table

Ahí es donde se produce el error, ahora... por que? no tengo la menor idea ...
OK, Pero dime ya puedes ingresar el contenido a tu DB? es decir en el campo "red1"
  #13 (permalink)  
Antiguo 24/01/2010, 13:09
 
Fecha de Ingreso: mayo-2009
Mensajes: 147
Antigüedad: 15 años
Puntos: 1
Respuesta: Problema UPDATE y PHP (Misterioso error)

si ya puedo ahora estoy viendo porque no puedo instanciar una fuking clase.. me estoy volviendo loco mal

AHORA PARECE QUE SE COLGÓ SERVIDOR, PORQUE ME DICE PROBLEMAS EN EL SERVIDOR

Última edición por trombonete; 24/01/2010 a las 13:12 Razón: R

Etiquetas: update
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 23:21.