Foros del Web » Programando para Internet » PHP »

Script Ingresa un dato en cada refresh

Estas en el tema de Script Ingresa un dato en cada refresh en el foro de PHP en Foros del Web. Ingreso los valores, apreto enviar y me guarda bien los datos. PERO los guarda DOS veces. Uno con el valor que yo envie y otro ...
  #1 (permalink)  
Antiguo 19/05/2007, 13:42
 
Fecha de Ingreso: marzo-2002
Mensajes: 42
Antigüedad: 22 años, 1 mes
Puntos: 0
Script Ingresa un dato en cada refresh

Ingreso los valores, apreto enviar y me guarda bien los datos. PERO los guarda DOS veces. Uno con el valor que yo envie y otro con una "," (coma).

Cada vez que refresco el navegador guarda nuevamente los ultimos datos ingresados (aunque no aparescan en los campos).

Aqui va el codigo.

Código PHP:
<?PHP

require("conexion_mysql.inc");
require(
"inscrip2.INC");


$db conectar_base_datos();



$firstname$_REQUEST['nombre'];
$lastname=$_REQUEST['apellido'];
$birthday=$_REQUEST['fecha'];
$nation=$_REQUEST['nation'];
$info=$_REQUEST['info'];
$checked_out=$_REQUEST['checked_out'];
$checked_out_time=$_REQUEST['checked_out_time'];

$s=inscrip($nombre,$apellido,$fecha,$nation,$info,$checked_out,$checked_out_time,$db);
echo 
'INSCRIPCION OK';

?>

<html>
<head>

</head>

 
    <FORM ACTION="jugadores.php" METHOD="GET">

                      <table width="1156" border="0" cellspacing="0" cellpadding="3" align="center">

            
            

            <tr> 
                <td  width='54'>Nombre:</td>
                <td width="512">     
                <input type="text" name="nombre" size="20" maxlength="32" tabindex="9">
                </td>
            </tr>
            
            <tr> 
                <td  width='54'>Apellido:</td>
                <td width="512">     
                <input type="text" name="apellido" size="20" maxlength="32" tabindex="9">
                </td>
            </tr>

            <tr> 
                <td  width='54'>Fecha de Nacimiento: AÑO-MES-DIA</td>
                <td width="512">     
                <input type="text" name="fecha" size="20" maxlength="32" tabindex="9" value="1980-10-10">
                </td>
            </tr>    
    
            
            <tr> 
                <td  width='54'>Nacionalidad:</td>
                <td width="512"> 
                <input type="text" name="nation" size="20" maxlength="32" tabindex="9">
                </td>
            </tr>    

            <tr> 
                <td  width='54'>Equipo:</td>
                <td width="512"> 
                <input type="text" name="info" size="20" maxlength="32" tabindex="9">
                </td>
            </tr>
            
            <tr> 
                <td  width='54'></td>
                <td width="512">     
                <input type="hidden" name="checked_out" size="20" maxlength="32" tabindex="9" value="0">
                </td>
            </tr>  

            <tr> 
                <td  width='54'></td>
                <td width="512">     
                <input type="hidden" name="checked_out_time" size="20" maxlength="32" tabindex="9" value="0000-00-00 00:00:00">
                </td>
            </tr>
                        
            
        </table>
        
                      <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        
        <INPUT TYPE="submit" VALUE="Enviar"> </p>
    </form>

</html>
Aqui el de la funcion

Código PHP:
<?php 
function inscrip($nombre,$apellido,$fecha,$nation,$info,$checked_out,$checked_out_time,$db)
{
    global 
$db;
   
echo 
mysql_error($db); 
    
  
$upd "INSERT INTO jos_joomleague_players (id,firstname,lastname,birthday,nation,info,checked_out,checked_out_time) VALUES('','$nombre','$apellido','$fecha','$nation','$info','$checked_out','$checked_out_time')";
  

  
$res mysql_query($upd,$db);
  if(!
$res)
    return(
0);
  return(
1);
    }


    

    

      
      
?>

gracias por ayudar..
  #2 (permalink)  
Antiguo 19/05/2007, 13:46
 
Fecha de Ingreso: marzo-2007
Mensajes: 347
Antigüedad: 17 años, 1 mes
Puntos: 2
Re: Script Ingresa un dato en cada refresh

Este codigo:

Código:
<?PHP 

require("conexion_mysql.inc"); 
require("inscrip2.INC"); 


$db = conectar_base_datos(); 



$firstname= $_REQUEST['nombre']; 
$lastname=$_REQUEST['apellido']; 
$birthday=$_REQUEST['fecha']; 
$nation=$_REQUEST['nation']; 
$info=$_REQUEST['info']; 
$checked_out=$_REQUEST['checked_out']; 
$checked_out_time=$_REQUEST['checked_out_time']; 

$s=inscrip($nombre,$apellido,$fecha,$nation,$info,$checked_out,$checked_out_time,$db); 
echo 'INSCRIPCION OK'; 

?> 

<html> 
<head> 

</head> 

  
    <FORM ACTION="jugadores.php" METHOD="GET"> 

                      <table width="1156" border="0" cellspacing="0" cellpadding="3" align="center"> 

             
             

            <tr>  
                <td  width='54'>Nombre:</td> 
                <td width="512">      
                <input type="text" name="nombre" size="20" maxlength="32" tabindex="9"> 
                </td> 
            </tr> 
             
            <tr>  
                <td  width='54'>Apellido:</td> 
                <td width="512">      
                <input type="text" name="apellido" size="20" maxlength="32" tabindex="9"> 
                </td> 
            </tr> 

            <tr>  
                <td  width='54'>Fecha de Nacimiento: AÑO-MES-DIA</td> 
                <td width="512">      
                <input type="text" name="fecha" size="20" maxlength="32" tabindex="9" value="1980-10-10"> 
                </td> 
            </tr>     
     
             
            <tr>  
                <td  width='54'>Nacionalidad:</td> 
                <td width="512">  
                <input type="text" name="nation" size="20" maxlength="32" tabindex="9"> 
                </td> 
            </tr>     

            <tr>  
                <td  width='54'>Equipo:</td> 
                <td width="512">  
                <input type="text" name="info" size="20" maxlength="32" tabindex="9"> 
                </td> 
            </tr> 
             
            <tr>  
                <td  width='54'></td> 
                <td width="512">      
                <input type="hidden" name="checked_out" size="20" maxlength="32" tabindex="9" value="0"> 
                </td> 
            </tr>   

            <tr>  
                <td  width='54'></td> 
                <td width="512">      
                <input type="hidden" name="checked_out_time" size="20" maxlength="32" tabindex="9" value="0000-00-00 00:00:00"> 
                </td> 
            </tr> 
                         
             
        </table> 
         
                      <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
         
        <INPUT TYPE="submit" VALUE="Enviar"> </p> 
    </form> 

</html>
cambialo por:

Código:
<?PHP 

require("conexion_mysql.inc"); 
require("inscrip2.INC"); 


$db = conectar_base_datos(); 

if($_GET['nombre'] != ''){

$firstname= $_REQUEST['nombre']; 
$lastname=$_REQUEST['apellido']; 
$birthday=$_REQUEST['fecha']; 
$nation=$_REQUEST['nation']; 
$info=$_REQUEST['info']; 
$checked_out=$_REQUEST['checked_out']; 
$checked_out_time=$_REQUEST['checked_out_time']; 

$s=inscrip($nombre,$apellido,$fecha,$nation,$info,$checked_out,$checked_out_time,$db); 
echo 'INSCRIPCION OK'; 
}
?> 

<html> 
<head> 

</head> 

  
    <FORM ACTION="jugadores.php" METHOD="GET"> 

                      <table width="1156" border="0" cellspacing="0" cellpadding="3" align="center"> 

             
             

            <tr>  
                <td  width='54'>Nombre:</td> 
                <td width="512">      
                <input type="text" name="nombre" size="20" maxlength="32" tabindex="9"> 
                </td> 
            </tr> 
             
            <tr>  
                <td  width='54'>Apellido:</td> 
                <td width="512">      
                <input type="text" name="apellido" size="20" maxlength="32" tabindex="9"> 
                </td> 
            </tr> 

            <tr>  
                <td  width='54'>Fecha de Nacimiento: AÑO-MES-DIA</td> 
                <td width="512">      
                <input type="text" name="fecha" size="20" maxlength="32" tabindex="9" value="1980-10-10"> 
                </td> 
            </tr>     
     
             
            <tr>  
                <td  width='54'>Nacionalidad:</td> 
                <td width="512">  
                <input type="text" name="nation" size="20" maxlength="32" tabindex="9"> 
                </td> 
            </tr>     

            <tr>  
                <td  width='54'>Equipo:</td> 
                <td width="512">  
                <input type="text" name="info" size="20" maxlength="32" tabindex="9"> 
                </td> 
            </tr> 
             
            <tr>  
                <td  width='54'></td> 
                <td width="512">      
                <input type="hidden" name="checked_out" size="20" maxlength="32" tabindex="9" value="0"> 
                </td> 
            </tr>   

            <tr>  
                <td  width='54'></td> 
                <td width="512">      
                <input type="hidden" name="checked_out_time" size="20" maxlength="32" tabindex="9" value="0000-00-00 00:00:00"> 
                </td> 
            </tr> 
                         
             
        </table> 
         
                      <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
         
        <INPUT TYPE="submit" VALUE="Enviar"> </p> 
    </form> 

</html>
  #3 (permalink)  
Antiguo 19/05/2007, 13:52
 
Fecha de Ingreso: marzo-2002
Mensajes: 42
Antigüedad: 22 años, 1 mes
Puntos: 0
Re: Script Ingresa un dato en cada refresh

Gracias nuevamente, funciona Perfecto :D
  #4 (permalink)  
Antiguo 19/05/2007, 17:34
Avatar de geq
geq
 
Fecha de Ingreso: agosto-2006
Ubicación: Rosario
Mensajes: 655
Antigüedad: 17 años, 8 meses
Puntos: 22
Re: Script Ingresa un dato en cada refresh

hola
como recomendacion nada mas ^^: no conviene procesar formularios con el mismo script que genera la pagina,, es decir si tu form esta en jugadores.php, que lo procese otro script (do_jugadores.php, por ejemplo) y luego regrese a la otra pagina.

perdon que me meta xD

exitos!
  #5 (permalink)  
Antiguo 19/05/2007, 17:43
 
Fecha de Ingreso: marzo-2007
Mensajes: 347
Antigüedad: 17 años, 1 mes
Puntos: 2
Re: Script Ingresa un dato en cada refresh

Ya, eso yo ya lo se, pero, el lo que necesitaba era que le solucionase el problema, hay lo tiene xD

Un saludo
  #6 (permalink)  
Antiguo 19/05/2007, 18:09
Avatar de geq
geq
 
Fecha de Ingreso: agosto-2006
Ubicación: Rosario
Mensajes: 655
Antigüedad: 17 años, 8 meses
Puntos: 22
Re: Script Ingresa un dato en cada refresh

si sta bien jja,, era solo como aclaracion por si no lo sabias (hay mucha gente qe lo hace) porqe me parecio qe staba hecho asi ^^


exitos
  #7 (permalink)  
Antiguo 19/05/2007, 18:27
(Desactivado)
 
Fecha de Ingreso: diciembre-2006
Mensajes: 529
Antigüedad: 17 años, 4 meses
Puntos: 11
Re: Script Ingresa un dato en cada refresh

Está muy bueno el comentario.
Sobre todo para los que queremos saber el por qué de todo.

Ya que lo comentaron sería bueno especificar el por qué no conviene procesar el formulario en la misma página que lo muestra y en el caso de que todos los datos estén correcto redirigirlos a otra página con un header de modo que cuando quieran actualizar la página los datos no sean reenviados al form.

Estaría bueno especificar, no obstante, en puntos claros por qué no conviene.

Espero sus comentarios.
  #8 (permalink)  
Antiguo 19/05/2007, 18:33
Avatar de geq
geq
 
Fecha de Ingreso: agosto-2006
Ubicación: Rosario
Mensajes: 655
Antigüedad: 17 años, 8 meses
Puntos: 22
Re: Script Ingresa un dato en cada refresh

bueno me disculpo,, deberia haber dado el por qe cuando dije qe no conviene (qe bobo,)

la principal razon es esa, como bien dijo usermax, para que no se reenvie la informacion al acutalizar la pagina, o incluso volver a visitarla en algunos casos. comprobar que se haya enviado el formulario no sirve de nada en este caso,,

a demas complica el codigo del script,, programar por modulos, aunque sea en esta forma simple, es mucho mas eficiente, no tanto tal vez (siempre depende del proyecto,claro) por rendimiento del sistema, sino del mismo programador (se entiende no O.o?)

otra razon a mi entender no hay ^^ si me gustaria saber si las hay o.o,,

exitos!
  #9 (permalink)  
Antiguo 19/05/2007, 20:56
(Desactivado)
 
Fecha de Ingreso: diciembre-2006
Mensajes: 529
Antigüedad: 17 años, 4 meses
Puntos: 11
Re: Script Ingresa un dato en cada refresh

geq, estoy de acuerdo.
Estuve visitando tus webs, muy interesantes.
  #10 (permalink)  
Antiguo 19/05/2007, 20:59
Avatar de geq
geq
 
Fecha de Ingreso: agosto-2006
Ubicación: Rosario
Mensajes: 655
Antigüedad: 17 años, 8 meses
Puntos: 22
Re: Script Ingresa un dato en cada refresh

bueno muchas gracias ^^
cualqier cosa ya sabes aqi stoi

exitos!
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 14:50.