petstat.php
<?php
include("head.php");
include("config.php");
$pid = $_GET['pid'];
?>
<?
$query = " SELECT pname, petname, currentcost, pimage, experience, pstatspeed, pstatattack, pstatdefense, pstathp, statpower, powner FROM petowns WHERE pid = '".$pid."' ";
$result = mysql_query($query) or die(mysql_error());
list($name, $nickname, $currentcost, $pimage, $experience, $speed, $attack, $defense, $hp, $power, $owner) = mysql_fetch_row($result);
if(empty($nickname)){
$nickname = $name;
}
if($owner == $id){
//max statpoints
$mxstp = $experience / 10;
//end
//max HPUP
$mxhtp = $experience / 5;
//end
?>
<b><p>Update <? echo $nickname; ?>'s stats</p></b><br />
<center><img src="<? echo $pimage; ?>"><br />
<?
echo '<p>
Blexperience to bust <font size="+3">'.$experience.'</font>
</p><p class="howto">How to update stats. Experience is calculated like this
Ten Blexperience points is equal to One StatPoint(for defense, attack, speed, power)<br />
Five Blexperience points is equal to One HPUP(for HP)</p><p>
<br />
<table>
<tr><td>Speed: '.$speed.'</td><td>
<form method="post" action="updatestat.php?statname=speed&pid='.$pid.'">
<input type="hidden" value="'.$mxstp.'" name="max">
<b>MAXIMUM StatPoint(s) = '.$mxstp.'</b> | Amount to update: <input type="text" value="0"><input type="submit" value="Up It!"></form>
</td></tr><tr><td>
Attack: '.$attack.'</td><td>
<form method="post" action="updatestat.php?statname=attack&pid='.$pid.'">
<input type="hidden" value="'.$mxstp.'" name="max">
<b>MAXIMUM StatPoint(s) = '.$mxstp.'</b> | Amount to update: <input type="text" value="0" name="up"><input type="submit" value="Up It!"></form>
</td></tr><tr><td>
Defense: '.$defense.'</td><td>
<form method="post" action="updatestat.php?statname=defense&pid='.$pid.'">
<input type="hidden" value="'.$mxstp.'" name="max">
<b>MAXIMUM StatPoint(s) = '.$mxstp.'</b> | Amount to update: <input type="text" value="0" name="up"><input type="submit" value="Up It!"></form>
</td></tr><tr><td>
HP: '.$hp.'</td><td>
<form method="post" action="updatestat.php?statname=HP&pid='.$pid.'">
<input type="hidden" value="'.$mxhtp.'" name="max">
<b>MAXIMUM HPUP(s) = '.$mxhtp.'</b> | Amount to update: <input type="text" value="0" name="up"><input type="submit" value="Up It!"></form>
</td></tr><tr><td>
Power: '.$power.'</td><td>
<form method="post" action="updatestat.php?statname=power&pid='.$pid.'">
<input type="hidden" value="'.$mxstp.'" name="max">
<b>MAXIMUM StatPoint(s) = '.$mxstp.'</b> | Amount to update: <input type="text" value="0" name="up"><input type="submit" value="Up It!"></form>
</td></tr></table>
</p>';
}else{
echo '<meta http-equiv="refresh" content="0; url=index.php">';
}
include("foot.php");
?>
updatestat.php
<?php
include("head.php");
include("config.php");
$pid = $_GET['pid'];
$stat = $_GET['statname'];
$max = $_POST['max'];
$up = $_POST['up'];
if($max < $up){
echo '<center>
<img src="images/load.gif">Updating Stats...
</center>
';
switch ($stat){
case "speed":
$query = "SELECT currentcost, experience, pstatspeed FROM petowns WHERE pid='".$pid."'";
break;
case "attack":
$query = "SELECT currentcost, experience, pstatattack FROM petowns WHERE pid='".$pid."'";
break;
case "defense":
$query = "SELECT currentcost, experience, pstatdefense FROM petowns WHERE pid='".$pid."'";
break;
case "HP":
$query = "SELECT currentcost, experience, pstathp FROM petowns WHERE pid='".$pid."'";
break;
case "power":
$query = "SELECT currentcost, experience, statpower FROM petowns WHERE pid='".$pid."'";
break;
}
$result = mysql_query($query) or die(mysql_error());
list($cost,$experience, $stat) = mysql_fetch_row($result);
$newcost = $up + $cost;
if($stat == 'HP'){
$eup = $up * 5;
}else{
$eup = $up * 10;
}
$newex = $experience - $eup;
$newstat = $stat + $up;
switch ($stat){
case "speed":
$query = "UPDATE petowns SET currentcost='".$newcost."', experience='".$newex."', pstatspeed='".$newstat."' WHERE pid='".$pid."'";
break;
case "attack":
$query = "UPDATE petowns SET currentcost='".$newcost."', experience='".$newex."', pstatattack='".$newstat."' WHERE pid='".$pid."'";
break;
case "defense":
$query = "UPDATE petowns SET currentcost='".$newcost."', experience='".$newex."', pstatdefense='".$newstat."' WHERE pid='".$pid."'";
break;
case "HP":
$query = "UPDATE petowns SET currentcost='".$newcost."', experience='".$newex."', pstathp='".$newstat."' WHERE pid='".$pid."'";
break;
case "power":
$query = "UPDATE petowns SET currentcost='".$newcost."', experience='".$newex."', statpower='".$newstat."' WHERE pid='".$pid."'";
break;
}
mysql_query($query) or die('Failed to add points');
echo '<meta http-equiv="refresh" content="0; url=petstat.php?pid='.$pid.'&updated=true">';
}else{
echo 'Not enough points!';
}
include("foot.php");
?>
it just doesn't update and then just redirects.
Also if $up is lower than the $max it just says not enough points whereas i want it to show that if $up is more than $max. Whats going on?
Everything is going wrong!