Hi im running a php game script call Kill Monsters on my website. Theres just a small thing that i dont know how to do. When they slay a monster (run the script posted bellow) they can easy press the F5 update buttom and saly monster and gain stats over and over agian without loosing a turn point. How can u fix this?
<?php
session_start();
include "connect.php";
?>
<?php
$player=$_SESSION['player'];
$userstats="SELECT * from km_users where playername='$player'";
$userstats2=mysql_query($userstats) or die("Could not get user stats");
$userstats3=mysql_fetch_array($userstats2);
$getnewpms="SELECT COUNT(*) from km_pms where receiver='$userstats3[ID]' and hasread='0'";
$getnewpms2=mysql_query($getnewpms) or die("Could not get new PMs");
$getnewpms3=mysql_result($getnewpms2,0);
if (isset($_SESSION['player']))
{
if(isset($_POST['submit']))
{
$player=$_SESSION['player'];
$playerstats1="SELECT * from km_users where playername='$player'";
$playerstats2=mysql_query($playerstats1) or die ("Could not find player");
$playerstats3=mysql_fetch_array($playerstats2);
if($playerstats3[numturns]<10)
{
print "<center><font color=#FFFFF face=Verdana size=1>You need at least 10 turn to kill a monster, please go back to <A href='index.php'>Main</a>.";
}
else
{
$monstername=$_POST['monstername'];
$monstername=strip_tags($monstername);
$selmonster="SELECT * from km_monsters where name='$monstername'";
$selmonster2=mysql_query($selmonster) or die ("Cannot select Monster");
$selmonster3=mysql_fetch_array($selmonster2);
if (!$selmonster3)
{
print "<center><font color=#FFFFF face=Verdana size=1>There is not a monster of that name";
}
else
{
$totalskill=$playerstats3[skillpts]+$selmonster3[skill];
$randomnumber=rand(1,$totalskill);
if($randomnumber<=$playerstats3[skillpts])
{
$newhp=$selmonster3[hpgain];
$gained=$selmonster3[pointsifkilled];
$gold=$selmonster3[goldworth];
$updateplayerstats="Update km_users set skillpts=skillpts+'$gained', gold=gold+'$gold',maxhp=maxhp+'$newhp',atkper=atkper+'$selmonster3[atkgain]' where playername='$player'";
mysql_query($updateplayerstats) or die("Could not update player stats");
$random=rand(1,5);
if ($random==1)
{
$text='Puts up a fight but your to strong he runs away!';
}
if ($random==2)
{
$text='Runs as soon as he sees you!';
}
if ($random==3)
{
$text='Limps away after you push him over the cliff edge!';
}
if ($random==4)
{
$text='Attacks with a massive attack but u dogde and unleash your attack which kills it!';
}
if ($random==5)
{
$text='Trys to trick you so u jump on his head!';
}
echo "<center><font face='Verdana' size='1' color='#FFFFFF'>Slay Monster";
print "<TABLE><TD BGCOLOR='3D3D3D'><center><font face='Verdana' size='1' color='#FFFFFF'>Won<P>The $selmonster3[name] $text
<P>Gained $selmonster3[goldworth] Gold & $selmonster3[pointsifkilled] Skill Points & $selmonster3[hpgain] HP & Atk Gain $selmonster3[atkgain]%";
print "<P><center><A href='index.php'>Kill more monsters</a></table>";
}
else
{
$random=rand(1,5); // You can have as many as u want if u had 1,20 make sure u make 20 texts
if ($random==1)
{
$text='Jumps out of a near by cave you had no chance!';
}
if ($random==2)
{
$text='Has been stalking you! He attacks with his teeth!';
}
if ($random==3)
{
$text='Hits you with a stick you faint!';
}
if ($random==4)
{
$text='Pushed you over the cliff you break both legs!';
}
if ($random==5)
{
$text='Hits you with a baseball bat!';
}
echo "<center><font face='Verdana' size='1' color='#FFFFFF'>Slay Monster";
print "<TABLE><TD BGCOLOR='3D3D3D'><center><font face='Verdana' size='1' color='#FFFFFF'>Lost<P>The $selmonster3[name] $text</table>";
print "<A href='index.php'>Kill more monsters</a>";
$updaterefresh="update km_users set numturns=numturns-1 where ID='$playerstats3[ID]'";
mysql_query($updaterefresh) or die("It just died");
}
}
}
}
}
else
{
print "You are not logged in, please <A href='login.php'>Login</a>";
}
?>
<br>
</td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#181818" width="450" id="AutoNumber14" align="center">
<tr>
<td>
<img border="0" src="images/footer-large.gif" width="450" height="14"></td>
</tr>
</table>
<p align="center"><br>
</td>
<td width="150" valign="top" height="522">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#181818" width="100%" id="AutoNumber16">
<tr>
<td width="100%">
<img border="0" src="images/pstats.gif" width="150" height="14"></td>
</tr>
</table>
<table border="1" cellpadding="2" cellspacing="2" style="border-collapse: collapse" bordercolor="#181818" width="100%" id="AutoNumber17">
<tr>
<td width="100%" bgcolor="3D3D3D">
<font face="Verdana" size="1" color="#FFFFFF">
<?php
if ($userstats3[legs]=='King Legs')
{
$legdef=4;
}
if ($userstats3[legs]=='New Legs')
{
$legdef=2;
}
if ($userstats3[legs]=='Old Legs')
{
$legdef=1;
}
if ($userstats3[shield]=='King Shield')
{
$shddef=4;
}
if ($userstats3[shield]=='New Shield')
{
$shddef=2;
}
if ($userstats3[shield]=='Old Shield')
{
$shddef=1;
}
if ($userstats3[armor]=='King Armor')
{
$armdef=4;
}
if ($userstats3[armor]=='New Armor')
{
$armdef=2;
}
if ($userstats3[armor]=='Old Armor')
{
$armdef=1;
}
if ($userstats3[weapon]=='King Axe')
{
$wepdef=4;
}
if ($userstats3[weapon]=='New Sword')
{
$wepdef=2;
}
if ($userstats3[weapon]=='Old Sword')
{
$wepdef=1;
}
$finalatk=$legdef+$wepdef+$armdef+$shddef+$userstats3[atkskill];
print "You Atk Skill: $userstats3[atkper] % $finalatk<br>";
print "You HP: $userstats3[hp] / $userstats3[maxhp]<br>";
print "Turns: $userstats3[numturns]<br>";
print "You skill pts: $userstats3[skillpts]<br>";
print "Your Honor: $userstats3[honor]<br>";
print "Your Gold: $userstats3[gold]<br>";
if ($userstats3[inclan]==1)
{
print "Your Clan: $userstats3[clanname]<br>";
}
?>