PHP interesse |
|
Beste mensen.. ik heb een shooting range script gemaakt.. de bedoeling is dus dat mensen moeten trainen om een nieuw wapen te mogen kopen.. maar nu heb ik dus ontdekt dat als je er voor 1 uur in wilt gaan.. en je drukt 2 keer op shootingrange.. ben je er al uit.. dus dan moet je geen uur meer bijven, en als je dus steeds 1 uur intypt.. heb je zo het beste wapen.. ik snap niet hoe dat komt.. ik zou graag jullie hulp kunnen gebruiken.
PS: dat gebeurt alleen bij 1 uur.. dus als ik bijvoorbeeld 5 uur invul.. is dat niet het geval.
het script ziet er als volgt uit:
<h3> Shooting Range</h3>
<?
if(isset($_POST['submit'])){
$hours=$_POST['hours'];
$cost=$hours*10000;
if(strlen($hours) > 2){ $hours = substr($hours, 0, 2); }
if($user['gun'] == 0){
echo "<font color=red>* You need to buy a gun first.</font>";
}
elseif($hours > 10){
echo "<font color=red>* This amount of hours is too high.</font>";
}
elseif(($user['practice']/10)+$hours > 10){
echo "<font color=red>* You can only train up to 100%.</font>";
}
elseif(ereg("[^0-9]", $hours)){
echo "<font color=red>* Invalid amount of hours.</font>";
}
elseif($user['money'] < $cost){
echo "<font color=red>* You don't have enough money.</font>";
}
elseif(empty($hours)){
echo "<font color=red>* Please fill in the amount of hours.</font>";
}
else{
$nmoney = $user['money'] - $cost;
$query = "UPDATE `users` SET `money` = '".$nmoney."' WHERE `id` = '".$user['id']."'";
mysql_query($query) or die(mysql_error());
$ntime = time() + (60 * 60 * $hours);
$query = "UPDATE `users` SET `shooting` = '".$ntime."' WHERE `id` = '".$user['id']."'";
mysql_query($query) or die(mysql_error());
$query = "UPDATE `users` SET `hours` = '".$hours."' WHERE `id` = '".$user['id']."'";
mysql_query($query) or die(mysql_error());
echo "You entered the shooting range.";
}
}
?>
<center>
<form action="?item=range" method="POST">
<table border=1 bordercolor=#000000 cellpadding=0 cellspacing=0 width=40%>
<th class="title" colspan="2">Shooting Range</th>
<tr><td colspan="2">You will earn ten percent of skill for every hour you spend at the shooting range. It costs $10,000 per hour.</td></tr>
<tr><td>Gun:</td><td>
<?
if($user['gun'] == 0){ echo "None"; }
elseif($user['gun'] == 1){ echo "Revolver"; }
elseif($user['gun'] == 2){ echo "Uzi"; }
elseif($user['gun'] == 3){ echo "M16"; }
elseif($user['gun'] == 4){ echo "Sniper"; }
elseif($user['gun'] == 5){ echo "Bazooka"; }
elseif($user['gun'] == 6){ echo "9MM"; }
?></td></tr>
<tr><td>Hours:</td><td><input type="text" name="hours" size="4" maxlength="3" class="text"></td></tr>
<tr><Td colspan=2 align="center">
<input type="submit" class="submit" name="submit" value="Enter shooting range">
</td></tr>
</table>
</form>
<br><br>
<table border=1 bordercolor=#000000 cellpadding=0 cellspacing=0 width=40%>
<th class="title" colspan="2">Current Skill</th>
<tr>
<td width="<?=$user['practice']; ?>%" bgcolor="green"> </td>
<td width="<?=(100 - $user['practice']); ?>%" align="left"><?=$user['practice']; ?>%</td>
</tr>
</table>
<h3> Shooting Range</h3> <? if(isset($_POST['submit'])){ $hours=$_POST['hours']; $cost=$hours*10000; if($user['gun'] == 0){ echo "<font color=red>* You need to buy a gun first.</font>"; } elseif($hours > 10){ echo "<font color=red>* This amount of hours is too high.</font>"; } elseif(($user['practice']/10)+$hours > 10){ echo "<font color=red>* You can only train up to 100%.</font>"; } elseif(ereg("[^0-9]", $hours)){ echo "<font color=red>* Invalid amount of hours.</font>"; } elseif($user['money'] < $cost){ echo "<font color=red>* You don't have enough money.</font>"; } echo "<font color=red>* Please fill in the amount of hours.</font>"; } else{ $nmoney = $user['money'] - $cost; $query = "UPDATE `users` SET `money` = '".$nmoney."' WHERE `id` = '".$user['id']."'"; $ntime = time() + (60 * 60 * $hours); $query = "UPDATE `users` SET `shooting` = '".$ntime."' WHERE `id` = '".$user['id']."'"; $query = "UPDATE `users` SET `hours` = '".$hours."' WHERE `id` = '".$user['id']."'"; echo "You entered the shooting range."; } } ?> <center> <form action="?item=range" method="POST"> <table border=1 bordercolor=#000000 cellpadding=0 cellspacing=0 width=40%> <th class="title" colspan="2">Shooting Range</th> <tr><td colspan="2">You will earn ten percent of skill for every hour you spend at the shooting range. It costs $10,000 per hour.</td></tr> <tr><td>Gun:</td><td> <? if($user['gun'] == 0){ echo "None"; } elseif($user['gun'] == 1){ echo "Revolver"; } elseif($user['gun'] == 2){ echo "Uzi"; } elseif($user['gun'] == 3){ echo "M16"; } elseif($user['gun'] == 4){ echo "Sniper"; } elseif($user['gun'] == 5){ echo "Bazooka"; } elseif($user['gun'] == 6){ echo "9MM"; } ?></td></tr> <tr><td>Hours:</td><td><input type="text" name="hours" size="4" maxlength="3" class="text"></td></tr> <tr><Td colspan=2 align="center"> <input type="submit" class="submit" name="submit" value="Enter shooting range"> </td></tr> </table> </form> <br><br> <table border=1 bordercolor=#000000 cellpadding=0 cellspacing=0 width=40%> <th class="title" colspan="2">Current Skill</th> <tr> <td width="<?=$user['practice']; ?>%" bgcolor="green"> </td> <td width="<?=(100 - $user['practice']); ?>%" align="left"><?=$user['practice']; ?>%</td> </tr> </table>
EDIT: Probleem opgelost.
|