I have the following code: Basically the gameconfig.php and top.php sets up the DB connection and the page display and retrieves a variable "npcid" via $_GET. The problem I am having is when the Delete query is not commented out, it tends to activate BEFORE my other query's despite being farther down in the code.
<?php
session_start();
include("gameconfig.php");
$title = "Local Training Dungeon- Battle Monster";
if(!$email || !$password){
error("field");
exit;}
if($playerinfo[jailtime] > 0){
error("jail");
exit;}
if($playerinfo[password] != $password){
error("password");}
else{
include("top.php");
//Get player location
$duser2 = mysql_query("SELECT * FROM tbl_dungeon_user WHERE id='$playerinfo[id]'");
$duser = mysql_fetch_array($duser2);
//get monster record
$dnpcgrid2 = mysql_query("SELECT * FROM tbl_dungeon_npcgrid WHERE id='$npcid'") or die(mysql_error());
$dnpcgrid = mysql_fetch_array($dnpcgrid2);
$dnpc2 = mysql_query("SELECT * FROM tbl_dungeon_npc WHERE id='$dnpcgrid[npcid]'");
$dnpc = mysql_fetch_array($dnpc2);
echo"test1<br>";
print_r($dnpcgrid);
print_r($dnpc);
echo"test2<br>";
//PERFORM CHECKS ON BOTH USER AND NPC
if(!$dnpcgrid){
echo "<center>Either you were too slow and this NPC has now been defeated by someone else, or this NPC doesn't exist!";
echo "<br><br><center>[<a href=game-dungeon.php?action=roam>Back to Grid Square</a>]</center>";
include("bottom.php");
exit;
}
// mysql_query("DELETE FROM tbl_dungeon_npcgrid WHERE id='$npcid'");
include("bottom.php");
}?>
This code returns the following:
test1
Array ( [0] => 12414751 [id] => 12414751 [1] => 35 [xco] => 35 [2] => 50 [yco] => 50 [3] => 1 [zco] => 1 [4] => 41 [npcid] => 41 [5] => 324 [level] => 324 ) Array ( [0] => 41 [id] => 41 [1] => Vampire Lord [name] => Vampire Lord [2] => Bat Swarm [wepname] => Bat Swarm [3] => [image] => [4] => 300 [level] => 300 [5] => 335 [level2] => 335 [6] => 50000 [hp] => 50000 [7] => 2500 [agility] => 2500 [8] => 2495 [strength] => 2495 [9] => 2000 [armor] => 2000 [10] => 10500 [damage] => 10500 [11] => 90 [gold] => 90 [12] => 90 [exp] => 90 ) test2
Now, if I uncomment the delete query and run it on THE EXACT SAME RECORD:
<?php
session_start();
include("gameconfig.php");
$title = "Local Training Dungeon- Battle Monster";
if(!$email || !$password){
error("field");
exit;}
if($playerinfo[jailtime] > 0){
error("jail");
exit;}
if($playerinfo[password] != $password){
error("password");}
else{
include("top.php");
//Get player location
$duser2 = mysql_query("SELECT * FROM tbl_dungeon_user WHERE id='$playerinfo[id]'");
$duser = mysql_fetch_array($duser2);
//get monster record
$dnpcgrid2 = mysql_query("SELECT * FROM tbl_dungeon_npcgrid WHERE id='$npcid'") or die(mysql_error());
$dnpcgrid = mysql_fetch_array($dnpcgrid2);
$dnpc2 = mysql_query("SELECT * FROM tbl_dungeon_npc WHERE id='$dnpcgrid[npcid]'");
$dnpc = mysql_fetch_array($dnpc2);
echo"test1<br>";
print_r($dnpcgrid);
print_r($dnpc);
echo"test2<br>";
//PERFORM CHECKS ON BOTH USER AND NPC
if(!$dnpcgrid){
echo "<center>Either you were too slow and this NPC has now been defeated by someone else, or this NPC doesn't exist!";
echo "<br><br><center>[<a href=game-dungeon.php?action=roam>Back to Grid Square</a>]</center>";
include("bottom.php");
exit;
}
mysql_query("DELETE FROM tbl_dungeon_npcgrid WHERE id='$npcid'");
include("bottom.php");
}?>
I get this result:
test1
test2
Either you were too slow and this NPC has now been defeated by someone else, or this NPC doesn't exist!
[Back to Grid Square]
Now can anyone tell me why?