Re: Project Z Help thread.
Posted: Tue Jul 13, 2010 9:56 pm
Thank you all for your help! 
I've tried a lot of logic debugging, i'm still unsure of the problem. I'm not sure about anyone else, but I always like to rid myself of these bugs before continuing onto something else
Now; let's see - I've re-done the database, the field is "townhall" and the table is "housing". The value does update whenever the script is run, as it should do. It is entering as a tiny integer.
The whole script is as follows:
Once the first town hall is built, the database updates, adds in the townhall information with the value "1" as it's supposed to.
If someone else tries to construct one, it goes ahead and builds it despite the validation. Hm, any ideas?
I've tried a lot of logic debugging, i'm still unsure of the problem. I'm not sure about anyone else, but I always like to rid myself of these bugs before continuing onto something else
Now; let's see - I've re-done the database, the field is "townhall" and the table is "housing". The value does update whenever the script is run, as it should do. It is entering as a tiny integer.
The whole script is as follows:
Code: Select all
<?php
include_Once '../connect.php';
session_start();
?>
<?php
if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("Could not get user stats");
$playerinfo3=mysql_fetch_array($playerinfo2);
print "<input type='hidden' name='id' value='$playerinfo3[id]'>";
$updaterefresh="update players set lastattacked=0 where ID='$playerinfo3[id]'";
mysql_query($updaterefresh) or die("Died");
}
else
{
print "Sorry, not logged in please <A href='../login.php'>Login</a><br>";
exit;
}
?>
<link href="../style1.css" rel="stylesheet" type="text/css" />
<div id="centertable01">
<?php $pid = $playerinfo3['id'];
$imageid=$_POST['id'];
$tag=$_POST['tag'];
$tag="tag".$tag;
$location = $playerinfo3['location'];
$shname = $_POST['name'];
$numb="SELECT townhall from housing where mapr='$playerinfo3[mapr]' AND mapc='$playerinfo3[mapc]'";
$numb2=mysql_query($numb) or die("Could not select information");
$numb3 = mysql_fetch_array($numb2);
if ($numb3['townhall'] == 1)
{
echo "There is already a town hall established here!";
echo "<center><br><A href='build.php'>Go Back";
exit;
}
if ($shname == NULL)
{
echo " You did not enter a name! Try again<br>";
echo "<center><br><A href='buildtownhall.php'>Go Back";
exit;
}
if ($playerinfo3['credits'] < 200000)
{
echo "You cannot afford to build a Town Hall here.<br>";
echo "<center><br><A href='build.php'>Go Back";
exit;
}
else
{
$randid = rand(150,500000);
$SQL = "INSERT into housing(pname, name, townhall, lvl, randid, mapr,mapc) VALUES ('$playerinfo3[name]','$shname','1','1','$randid','$playerinfo3[mapr]','$playerinfo3[mapc]')";
mysql_query($SQL) or die("could not add shop");
$updateplayers="Update players set credits=credits-200000 where id='$pid'";
mysql_query($updateplayers) or die("Could not update player stats");
$housing="SELECT * from housing WHERE pname='$playerinfo3[name]' AND randid = $randid";
$housing2=mysql_query($housing) or die("Could not get housing");
$housing3=mysql_fetch_array( $housing2);
$pid = $housing3['id'];
$randid = rand(150,500000);
$SQL = "INSERT into townhalls(pid, pname, name, lvl, randid, greeting) VALUES ('$pid','$playerinfo3[name]','$shname','1','$randid','Welcome to the $shname town hall!')";
mysql_query($SQL) or die("could not add town hall");
$SQL = "INSERT into townhallmembers(pid, name, rank,level,glevel) VALUES ('$pid','$playerinfo3[name]','Founder','$playerinfo3[level]',5)";
mysql_query($SQL) or die("could not add council member");
///////////////////////////add to map////////////////////////////////////////
$updateplayers="Update map set house=house+1, mname='$shname' where mapr='$playerinfo3[mapr]' AND mapc='$playerinfo3[mapc]'";
mysql_query($updateplayers) or die("Could not update map info");
$mapinfo="SELECT mapr,mapc,house from map where mapr='$playerinfo3[mapr]' AND mapc='$playerinfo3[mapc]'";
$mapinfo2=mysql_query($mapinfo) or die("Could not map");
$mapinfo3=mysql_fetch_array($mapinfo2);
if ($mapinfo3['house'] >= 25)
{
$updateplayers="Update map set tile='metro' where mapr='$playerinfo3[mapr]' AND mapc='$playerinfo3[mapc]'";
mysql_query($updateplayers) or die("Could not update player stats");
}
elseif ($mapinfo3['house'] >= 15)
{
$updateplayers="Update map set tile='guild4' where mapr='$playerinfo3[mapr]' AND mapc='$playerinfo3[mapc]'";
mysql_query($updateplayers) or die("Could not update player stats");
}
elseif ($mapinfo3['house'] >= 10)
{
$updateplayers="Update map set tile='guild3' where mapr='$playerinfo3[mapr]' AND mapc='$playerinfo3[mapc]'";
mysql_query($updateplayers) or die("Could not update player stats");
}
elseif ($mapinfo3['house'] >= 5)
{
$updateplayers="Update map set tile='guild3' where mapr='$playerinfo3[mapr]' AND mapc='$playerinfo3[mapc]'";
mysql_query($updateplayers) or die("Could not update player stats");
}
elseif ($mapinfo3['house'] >= 2)
{
$updateplayers="Update map set tile='guild2' where mapr='$playerinfo3[mapr]' AND mapc='$playerinfo3[mapc]'";
mysql_query($updateplayers) or die("Could not update player stats");
}
elseif ($mapinfo3['house'] == 1)
{
$updateplayers="Update map set tile='guild' where mapr='$playerinfo3[mapr]' AND mapc='$playerinfo3[mapc]'";
mysql_query($updateplayers) or die("Could not update player stats");
}
/////////////////////////////////////////////////////////////////////////////////////
echo "<center><big>A Town Hall has been Built</big></center></br>";
echo "<center><br><A href='../locations/map.php'>Go Back";
}
?>
</div>
If someone else tries to construct one, it goes ahead and builds it despite the validation. Hm, any ideas?