Foros del Web » Programando para Internet » PHP »

inserta 2 veces

Estas en el tema de inserta 2 veces en el foro de PHP en Foros del Web. buenas tengo un problema que me trae de cabeza hago un query para insertar en la bd y me lo hace 2 veces Código PHP: ...
  #1 (permalink)  
Antiguo 27/02/2010, 14:14
 
Fecha de Ingreso: abril-2009
Mensajes: 356
Antigüedad: 15 años
Puntos: 7
inserta 2 veces

buenas tengo un problema que me trae de cabeza

hago un query para insertar en la bd y me lo hace 2 veces

Código PHP:
<? 

if(!$_GET['reclutar'] == ""){

$tiempo $_GET['finaliza'] + time();

mysql_query("insert into Reclutando (Propietario ,Nombre ,Finaliza) VALUES ('".$_SESSION['nombre']."','".$_GET['reclutar']."','".$tiempo."')");

}

?>
<? 

$reclutando 
mysql_query("select * from Reclutando where Propietario = '".$_SESSION['nombre']."'");
$reclutando mysql_fetch_array($reclutando);

$buscar mysql_query("select * from A_soldados where Nombre = '".$reclutando[1]."'");
$buscar mysql_fetch_array($buscar);

if(
$reclutando[2] < time()){

$cantidad $buscar[8];

mysql_query("insert into Reclutado (Propietario ,Nombre ,Cantidad) VALUES ('".$_SESSION['nombre']."','".$reclutando[1]."','".$cantidad."')");

mysql_query("DELETE FROM `Reclutando` WHERE Propietario = '".$_SESSION['nombre']."' limit 1");

}

?>
<? 

$reclutando 
mysql_query("select * from Reclutando where Propietario = '".$_SESSION['nombre']."'");
$reclutando mysql_fetch_array($reclutando);

if(
$reclutando[0] == $_SESSION['nombre']){

$buscar mysql_query("select * from A_soldados where Nombre = '".$reclutando[1]."'");
$buscar mysql_fetch_array($buscar);

?>

<table width="500" border="0" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->
  <tr>
    <td width="75" rowspan="4" valign="top"><img name="" src="<? echo $buscar[2]; ?>" width="75" height="75" alt="" /></td>
    <td width="20" height="20"></td>
    <td valign="top"><font color="#00CC66"><? echo $buscar[0]; ?></font> <font color="#CCCCCC" size="-1"><a href="../ficha_soldados.php?nombre=<? echo $buscar[0]; ?>">(ficha)</a></font></td>
  <td width="200"></td>
  </tr>
  <tr>
    <td height="12"></td>
    <td width="205"></td>
    <td></td>
  </tr>
  
  <tr>
    <td height="20"></td>
    <td valign="top"><font size="-1">Cantidad: <? echo $buscar[8]; ?></font></td>
  <td valign="top"><div align="center"><div id="txt1"><? echo $contador $reclutando[2] - time(); ?></div><script type="text/javascript">faltan("txt1");</script></div></td>
  </tr>
  
  
  
  <tr>
    <td height="23"></td>
    <td valign="top">
    
    <? $madera $buscar[9]; if($buscar_recursos[2] < $madera){ echo '<font color="#990000">'; echo $madera; }else{ echo '<font color="#009933">'; echo $madera; } ?>    </font>
                    
    <img name="" src="../imagenes/objetos/hierro.png" width="20" height="20" alt="" /> 
    <? $hierro $buscar[10]; if($buscar_recursos[3] < $hierro){ echo '<font color="#990000">'; echo $hierro; }else{ echo '<font color="#009933">'; echo $hierro; } ?>    </font>
                    
    <img name="" src="../imagenes/objetos/joyas.png" width="20" height="20" alt="" /> 
    <? $joyas $buscar[11]; if($buscar_recursos[3] < $joyas){ echo '<font color="#990000">'; echo $joyas; }else{ echo '<font color="#009933">'; echo $joyas; } ?>    </font>    </td>
  <td>&nbsp;</td>
  </tr>
  
  <tr>
    <td height="20">&nbsp;</td>
    <td></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>

<?


}else{


$buscar_recursos mysql_query("select * from Recursos where Usuario = '".$_SESSION['nombre']."'");
$buscar_recursos mysql_fetch_array($buscar_recursos);

$buscar mysql_query("select * from A_soldados");

while(
$row mysql_fetch_row($buscar)){


?>

<table width="500" border="0" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->
  <tr>
    <td width="75" rowspan="4" valign="top"><img name="" src="<? echo $row[2]; ?>" width="75" height="75" alt="" /></td>
    <td width="20" height="20"></td>
    <td valign="top"><font color="#00CC66"><? echo $row[0]; ?></font> <font color="#CCCCCC" size="-1"><a href="../ficha_soldados.php?nombre=<? echo $row[0]; ?>">(ficha)</a></font></td>
  <td width="200">&nbsp;</td>
  </tr>
  <tr>
    <td height="12"></td>
    <td width="205"></td>
    <td></td>
  </tr>
  
  <tr>
    <td height="20"></td>
    <td valign="top"><font size="-1">Cantidad: <? echo $row[8]; ?></font></td>
    <td rowspan="2" valign="top"><div align="center"><a href="../reclutar.php?reclutar=<? echo $row[0]; ?>&&finaliza=<? echo $row[3]; ?>">Reclutar</a></div></td>
  </tr>
  
  
  
  <tr>
    <td height="23"></td>
    <td valign="top">
    
    <? $madera $row[9]; if($buscar_recursos[2] < $madera){ echo '<font color="#990000">'; echo $madera; }else{ echo '<font color="#009933">'; echo $madera; } ?>    </font>
                    
    <img name="" src="../imagenes/objetos/hierro.png" width="20" height="20" alt="" /> 
    <? $hierro $row[10]; if($buscar_recursos[3] < $hierro){ echo '<font color="#990000">'; echo $hierro; }else{ echo '<font color="#009933">'; echo $hierro; } ?>    </font>
                    
    <img name="" src="../imagenes/objetos/joyas.png" width="20" height="20" alt="" /> 
    <? $joyas $row[11]; if($buscar_recursos[3] < $joyas){ echo '<font color="#990000">'; echo $joyas; }else{ echo '<font color="#009933">'; echo $joyas; } ?>    </font>    </td>
  </tr>
  
  <tr>
    <td height="20">&nbsp;</td>
    <td></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>

<? }} ?>
este es el codigo

es un poco confuso pero si me podeis ayudar ya no se k hacer
__________________
Cannabis; todo sobre el mundo de la marihuana
  #2 (permalink)  
Antiguo 27/02/2010, 14:24
Avatar de Fernand0  
Fecha de Ingreso: septiembre-2005
Ubicación: Buenos Aires
Mensajes: 610
Antigüedad: 18 años, 7 meses
Puntos: 19
Respuesta: inserta 2 veces

no veo problema, lo que si te digo es que usas muchas consultas, cosa que no es una buena costumbre

tal vez..

Código PHP:
Ver original
  1. if(!$_GET['reclutar'] == "")
y
Código PHP:
Ver original
  1. if($reclutando[2] < time())

checkea bien los valores y el get.. se dan las 2 condiciones y tenes los 2 ingresos

Última edición por Fernand0; 27/02/2010 a las 14:31
  #3 (permalink)  
Antiguo 27/02/2010, 14:25
Avatar de MarioAraque
Colaborador
 
Fecha de Ingreso: octubre-2009
Ubicación: Valencia
Mensajes: 1.398
Antigüedad: 14 años, 6 meses
Puntos: 265
Respuesta: inserta 2 veces

Deberias explicar un poco como funciona y para que es.
A lo que me refiero es que ahi se ven 2 inserts en tu codigo, quizas no estas poniendo bien alguna sentencia y, en algunas operaciones, inserta 2 veces cuando vos queres q lo haga solo 1.

Saludos.

Etiquetas: inserta
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 18:52.