Jump to content

mysql_query Double Posting? :S


Monk3h

Recommended Posts

My problem is that one of my mysql_query Insert into Strings is double posting and i have no idea why!? :S

 

 

This is the code that is double posting.

 

mysql_query("insert into tlog (owner, log) values($mytribe[id],'<span style=color:#009900>Your tribe Successfully attacked $enemytribe[name] and gained $landgain land.</span>')");

 

 

the output im getting isn't an exact double.. but it still shouldnt apear.

 

Output:

 

Your tribe Successfully attacked TEST TRIE BETA and gained 0 land. 

Your tribe Successfully attacked and gained 0 land.

 

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/103563-mysql_query-double-posting-s/
Share on other sites

Yeah, its in the DB twice.

 

This is some more of the code.

 

mysql_query("insert into tlog (owner, log) values($mytribe[id],'<span style=color:#009900>Your tribe Successfully attacked $enemytribe[name] and gained $landgain land.</span>')");

mysql_query("insert into tlog (owner, log) values($enemytribe[id],'<span style=color:#CC0000>Your tribe unsuccessfully Defended them selfs against an attack from $mytribe[name] and lost $landgain land.</span>')");

This is the entire Script. Iv posted it all because its prety small.

 

<?php $title = "Tribe War Room"; include("header.php"); ?>

<?php
$mytribe = mysql_fetch_array(mysql_query("select * from tribes where id=$stat[tribe]"));

      print "Welcome to the war room Commander $stat[user], Who's tribe would you like to attack today?<br><br>";
      print "<table><form method=post action=tribebattle.php?action=battle>";
      print "<tr><td>Tribe ID:</td><td><input type=text name=tid>  ";
      print "<input type=submit value=Attack></td></tr>";
      print "</form></table><br><br>Wins: <b>$mytribe[win]</b><br>Losses: <b>$mytribe[lose]</b><br><br><br>";

      if ($action == battle) {
  
  

  $enemytribe = mysql_fetch_array(mysql_query("select * from tribes where id=$tid"));
  
$unit1 = mysql_fetch_array(mysql_query("select * from dtroops where id=1"));
$unit2 = mysql_fetch_array(mysql_query("select * from dtroops where id=2"));
$unit3 = mysql_fetch_array(mysql_query("select * from dtroops where id=3"));
$unit4 = mysql_fetch_array(mysql_query("select * from dtroops where id=4"));
$unit5 = mysql_fetch_array(mysql_query("select * from troops where id=1"));
$unit6 = mysql_fetch_array(mysql_query("select * from troops where id=2"));
$unit7 = mysql_fetch_array(mysql_query("select * from troops where id=3"));
$unit8 = mysql_fetch_array(mysql_query("select * from troops where id=4"));
$unit9 = mysql_fetch_array(mysql_query("select * from troops where id=5"));
$unit10 = mysql_fetch_array(mysql_query("select * from troops where id=6"));

$unit1a = ($unit5[dmg] * $mytribe[Peasant]);
$unit2a = ($unit6[dmg] * $mytribe[ArmedPeasant]);
$unit3a = ($unit7[dmg] * $mytribe[Recruit]);
$unit4a = ($unit8[dmg] * $mytribe[TrainedAssasin]);
$unit5a = ($unit9[dmg] * $mytribe[Archer]);
$unit6a = ($unit10[dmg] * $mytribe[Rifleman]);

$unit1d = ($unit1[dmg] * $enemytribe[Wall]);
$unit2d = ($unit2[dmg] * $enemytribe[GuardTower]);
$unit3d = ($unit3[dmg] * $enemytribe[Catapult]);
$unit4d = ($unit4[dmg] * $enemytribe[WoodenTrap]);

$attack = ($unit1a + $unit2a + $unit3a + $unit4a + $unit5a + $unit6a);
$defence = ($unit1d + $unit2d + $unit3d + $unit4d);
$landcap = ($mytribe[land] / 2);
        $landloss = ($mytribe[land] / 10);
        $landgain = ($enemytribe[land] / 10);

if ($stat[id]  != $mytribe[owner]) {

Print "You are not the Tribe Owner, you do not have the authority to deploy your tribes troops.";
include ("footer.php");
exit;
}

if ($enemytribe[land] < $landcap){

Print "The enemies tribe is out of range!";
include ("footer.php");
exit;
}

if ($mytribe[energy] < 10){

Print"Your tribe does not have enough energy to do that!";
include ("footer.php");
exit;
}

if ($attack < 0){

Print "You dont have any troops, are you Crazy!?";
include ("footer.php");
exit;

}

if ($defence >= $attack){

Print "<span style=color:#CC0000>You lost the battle!</span>";
mysql_query("update tribes set lose=lose+1 where id=$mytribe[id]");
mysql_query("update tribes set win=win+1 where id=$enemytribe[id]");
mysql_query("update tribes set energy=energy-5 where id=$mytribe[id]");

mysql_query("insert into tlog (owner, log) values($mytribe[id],'<span style=color:#CC0000>Your tribe attacked $enemytribe[name] and Lost.</span>')");

mysql_query("insert into tlog (owner, log) values($enemytribe[id],'<span style=color:#009900>Your tribe Successfully Defended them selfs against an attack from $mytribe[name]</span>')");
include ("footer.php");
exit;

}else{

Print "<span style=color:#009900>You Won the battle!<br><br>You gained <b>$landgain</b> Land!</span>";
mysql_query("update tribes set lose=lose+1 where id=$enemytribe[id]");
mysql_query("update tribes set win=win+1 where id=$mytribe[id]");
mysql_query("update tribes set land=land+$landgain where id=$mytribe[id]");
mysql_query("update tribes set land=land-$landgain where id=$enemytribe[id]");
mysql_query("update tribes set energy=energy-10 where id=$mytribe[id]");

mysql_query("insert into tlog (owner, log) values($mytribe[id],'<span style=color:#009900>Your tribe Successfully attacked $enemytribe[name] and gained $landgain land.</span>')");

mysql_query("insert into tlog (owner, log) values($enemytribe[id],'<span style=color:#CC0000>Your tribe unsuccessfully Defended them selfs against an attack from $mytribe[name] and lost $landgain land.</span>')");
}}

?>

<?php include("footer.php"); ?>

Problem:

For some reason when i insert into my log table in my database it double Posts. the first post has all the $mytribe[id] stuff filled in as it should. The second post  is exactly the same but all the $stuff is left out. :s

 

Problem Code:

 

mysql_query("insert into tlog (owner, log) values($mytribe[id],'<span style=color:#009900>Your tribe Successfully attacked $enemytribe[name] and gained $landgain land.</span>')");

 

 

This is the code just before it:

 

Print "<span style=color:#009900>You Won the battle!<br><br>You gained <b>$landgain</b> Land!</span>";
mysql_query("update tribes set lose=lose+1 where id=$enemytribe[id]");
mysql_query("update tribes set win=win+1 where id=$mytribe[id]");
mysql_query("update tribes set land=land+$landgain where id=$mytribe[id]");
mysql_query("update tribes set land=land-$landgain where id=$enemytribe[id]");
mysql_query("update tribes set energy=energy-10 where id=$mytribe[id]");

 

 

 

 

This is the Complete Script:

 

<?php $title = "Tribe War Room"; include("header.php"); ?>

<?php
$mytribe = mysql_fetch_array(mysql_query("select * from tribes where id=$stat[tribe]"));

      print "Welcome to the war room Commander $stat[user], Who's tribe would you like to attack today?<br><br>";
      print "<table><form method=post action=tribebattle.php?action=battle>";
      print "<tr><td>Tribe ID:</td><td><input type=text name=tid>  ";
      print "<input type=submit value=Attack></td></tr>";
      print "</form></table><br><br>Wins: <b>$mytribe[win]</b><br>Losses: <b>$mytribe[lose]</b><br><br><br>";

      if ($action == battle) {
  
  

  $enemytribe = mysql_fetch_array(mysql_query("select * from tribes where id=$tid"));
  
$unit1 = mysql_fetch_array(mysql_query("select * from dtroops where id=1"));
$unit2 = mysql_fetch_array(mysql_query("select * from dtroops where id=2"));
$unit3 = mysql_fetch_array(mysql_query("select * from dtroops where id=3"));
$unit4 = mysql_fetch_array(mysql_query("select * from dtroops where id=4"));
$unit5 = mysql_fetch_array(mysql_query("select * from troops where id=1"));
$unit6 = mysql_fetch_array(mysql_query("select * from troops where id=2"));
$unit7 = mysql_fetch_array(mysql_query("select * from troops where id=3"));
$unit8 = mysql_fetch_array(mysql_query("select * from troops where id=4"));
$unit9 = mysql_fetch_array(mysql_query("select * from troops where id=5"));
$unit10 = mysql_fetch_array(mysql_query("select * from troops where id=6"));

$unit1a = ($unit5[dmg] * $mytribe[Peasant]);
$unit2a = ($unit6[dmg] * $mytribe[ArmedPeasant]);
$unit3a = ($unit7[dmg] * $mytribe[Recruit]);
$unit4a = ($unit8[dmg] * $mytribe[TrainedAssasin]);
$unit5a = ($unit9[dmg] * $mytribe[Archer]);
$unit6a = ($unit10[dmg] * $mytribe[Rifleman]);

$unit1d = ($unit1[dmg] * $enemytribe[Wall]);
$unit2d = ($unit2[dmg] * $enemytribe[GuardTower]);
$unit3d = ($unit3[dmg] * $enemytribe[Catapult]);
$unit4d = ($unit4[dmg] * $enemytribe[WoodenTrap]);

$attack = ($unit1a + $unit2a + $unit3a + $unit4a + $unit5a + $unit6a);
$defence = ($unit1d + $unit2d + $unit3d + $unit4d);
$landcap = ($mytribe[land] / 2);
        $landloss = ($mytribe[land] / 10);
        $landgain = ($enemytribe[land] / 10);

if ($stat[id]  != $mytribe[owner]) {

Print "You are not the Tribe Owner, you do not have the authority to deploy your tribes troops.";
include ("footer.php");
exit;
}

if ($enemytribe[land] < $landcap){

Print "The enemies tribe is out of range!";
include ("footer.php");
exit;
}

if ($mytribe[energy] < 10){

Print"Your tribe does not have enough energy to do that!";
include ("footer.php");
exit;
}

if ($attack < 0){

Print "You dont have any troops, are you Crazy!?";
include ("footer.php");
exit;

}

if ($defence >= $attack){

Print "<span style=color:#CC0000>You lost the battle!</span>";
mysql_query("update tribes set lose=lose+1 where id=$mytribe[id]");
mysql_query("update tribes set win=win+1 where id=$enemytribe[id]");
mysql_query("update tribes set energy=energy-5 where id=$mytribe[id]");

mysql_query("insert into tlog (owner, log) values($mytribe[id],'<span style=color:#CC0000>Your tribe attacked $enemytribe[name] and Lost.</span>')");

mysql_query("insert into tlog (owner, log) values($enemytribe[id],'<span style=color:#009900>Your tribe Successfully Defended them selfs against an attack from $mytribe[name]</span>')");
include ("footer.php");
exit;

}else{

Print "<span style=color:#009900>You Won the battle!<br><br>You gained <b>$landgain</b> Land!</span>";
mysql_query("update tribes set lose=lose+1 where id=$enemytribe[id]");
mysql_query("update tribes set win=win+1 where id=$mytribe[id]");
mysql_query("update tribes set land=land+$landgain where id=$mytribe[id]");
mysql_query("update tribes set land=land-$landgain where id=$enemytribe[id]");
mysql_query("update tribes set energy=energy-10 where id=$mytribe[id]");

mysql_query("insert into tlog (owner, log) values($mytribe[id],'<span style=color:#009900>Your tribe Successfully attacked $enemytribe[name] and gained $landgain land.</span>')");

mysql_query("insert into tlog (owner, log) values($enemytribe[id],'<span style=color:#CC0000>Your tribe unsuccessfully Defended them selfs against an attack from $mytribe[name] and lost $landgain land.</span>')");
}}

?>

<?php include("footer.php"); ?>

 

 

Please help. I have no idea why its doing this. I have used exactly the same string to add to the tlog table in other areas of the game and this dosnt happen. So confused.

Footer.php

 

</td></tr>
</table><br>
<br>
</td><td width=20% valign=top>

<table cellpadding=0 cellspacing=0 class=td width=100%>
	<tr><td style="border-bottom: solid 747d58 1px;" bgcolor=DDCC71 align=center>
		<b>Storage</b>
	</td></tr>
	<tr><td>
		<?php
		print "<center><b><u></b></u></center>";
print "<b>Rats Tails:</b> $stat[ratt]<br>";
print "<b>Chicken Feathers:</b> $stat[chickf]<br>";
print "<b>Wolf Hairs:</b> $stat[wolfh]<br>";
print "<b>Hunters Arrows:</b> $stat[hunta]<br>";
print "<b>Witches Brooms:</b> $stat[witchb]<br>";
print "<b>Cobra Fangs:</b> $stat[cobraf]<br>";
print "<b>Dragon Scales:</b> $stat[drags]<br><br>";
		if ($stat[mines] > 0) {
			print "<b>Burelia:</b> $stat[burelia]<br>";
			print "<b>Alethite:</b> $stat[alethite]<br><br>";

		}
		if ($stat[dams] > 0) {
			print "<b>LargeMouth Bass:</b> $stat[bass]<br>";
			print "<b>Saratoga:</b> $stat[saratoga]<br>";
		}



		?>
	</td></tr>
	</table><br>



		<table cellpadding=0 cellspacing=0 class=td width=100%>
		<tr><td style="border-bottom: solid 747d58 1px;" bgcolor=DDCC71 align=center>
			<b>Online Players</b>
		</td></tr>
		<tr><td>
			<?php
			$psel = mysql_query("select * from players order by id asc");
			$ctime = time();
			while ($pl = mysql_fetch_array($psel)) {
				$span = ($ctime - $pl[lpv]);
				if ($span <= 500) {
					if ($pl[rank] == Admin) {
						print "<img src=images/admin.gif>";
					} 		
					if ($pl[rank] == Staff) {
						print "<img src=Tiny_S.gif>";
					}					
	print "$pl[tag]<A href=view.php?view=$pl[id]>$pl[user]</a> ($pl[id])";							if ($pl[sub] > 0) {
		print "<img src=http://www.renhelp.net/images/tutorials/star.gif>";
					} print "<br>";		
					$numo = ($numo + 1);
				}
			}
			?>
		</td></tr>
		</table><br>
		<table cellpadding=0 cellspacing=0 class=td width=100%>
		<tr><td style="border-bottom: solid 747d58 1px;" bgcolor=DDCC71 align=center>
			<b>Game Stats</b>
		</td></tr>
		<tr><td>
			<?php
			$nump = @mysql_num_rows(mysql_query("select * from players"));
			$numw = @mysql_num_rows(mysql_query("select * from equipment where type='W'"));
			$numa = @mysql_num_rows(mysql_query("select * from equipment where type='A'"));
			print "<b>$nump</b> total players.<br>";
			print "<b>$numo</b> players online.<br>";
			print "<b>$numw</b> weapons.<br>";
			print "<b>$numa</b> armor.<br>";
			?>
		</td></tr>
		</table><br>
			<table cellpadding=0 cellspacing=0 class=td width=100%>
		<tr><td style="border-bottom: solid 747d58 1px;" bgcolor=DDCC71 align=center>
			<b>Vote for Rise of Kingdoms</b></td></tr>
		<tr><td>
<?php

print "Please vote using these links to help promote and support this game. For each vote you will receive <b>1 Diamond</b>. The more you vote, the more people see the game, and therefore the more people join and make the game more enjoyable!<br><br>";

if ($stat[vote] == N) {
print "<a href=vote.php?vote=1>Top 100 Arena</a><br>"; }
if ($stat[vote2] == N) {
print "<a href=vote.php?vote=2>Top 50 Onrpg</a><br>"; }
if ($stat[vote3] == N) {
print "<a href=vote.php?vote=3>Top Game Sites</a><br>"; }
if ($stat[vote4] == N) {
print "<a href=vote.php?vote=4>GTOP 100</a><br>"; }
if ($stat[vote5] == N) {
print "<a href=vote.php?vote=5>Game Sites 100</a><br>"; }
if ($stat[vote6] == N) {
print "<a href=vote.php?vote=6>Ultimate Top 200 Game Sites</a><br>"; }
if ($stat[vote7] == N) {
print "<a href=vote.php?vote=7>PHP Games Network</a>"; }

?>

</td></tr>
</td></tr>
		</table>
<center>

<!------------(C) 2008 Adam Miller and James Eley GNU Library or Lesser Public License (LGPL)------------>
</body>
</html>

The thing is its not jsut in this one place where things are being Doubled up.

 

Its all over my site. When you buy weapons you get 2 if you can offord it, when you take steps in the forrest it uses 2 instead of one. You still get both Steps worth of Stuff.. you just cant see the first step.

 

 

do you have any idea what could be causing this? =/

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.