Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
php help - in game cash?
hey
Im trying to make code for an online game im trying to build,
im trying to make a php page which will subtract the cost of the factory from the users cash, this is what i have so far:
<?php
$factory1 = "$12,000,000";
$factory2 = "$18,000,000";
$factory3 = "$24,000,000";
if ($cash|>$factory1);
echo "You have successfully built this factory";
else
{
echo "You do not have sufficient funds";
}
//deduct 12 million from the users cash
//
if ($cash|>$factory2);
echo "You have successfully built this factory";
else
{
echo "You do not have sufficient funds to complete the purchase";
}
//deduct 18million from users cash
//
?>
but i was wondering how to make it so that if they buy factory 1 then 12 million is deducted, and if they buy factory 2 then 18 million is deducted, also i was wondering how would i send the remaining cash after the purchase into the database?
is it INSERT INTO * cash WHERE cash = $cash; ?? or something similar
thanks :)
2 Answers
- GitlezLv 610 years agoFavorite Answer
<?php
$cash = 20000000;
$factories = Array(
'1' => 12000000,
'2' => 18000000,
'3' => 24000000
);
if(strlen($_POST['submit']) > 0){
$factoryCost = $factories[$_POST['factory']];
if ($cash >= $factoryCost){
$cash -= $factoryCost;
echo "You have successfully built factory #" . $_POST['factory'] . '<br />';
echo 'You have $' . number_format($cash) . ' remaining.<hr />';
}else{
echo 'You do not have sufficient funds. <span style="color: #900;">$' . number_format($cash - $factoryCost) . '</span><hr />';
}
}
?>
<html>
<head>
<title>Factory Purchasing</title>
</head>
<body>
<form method="POST">
You Currently have $<?php echo number_format($cash); ?> in the bank.<br />
Select Factory to purchase:<br />
<?php
foreach($factories as $num=>$cost){
echo '<input type="radio" name="factory" value="' . $num . '" />#' . $num . ' ($' . number_format($cost) . ')<br />';
}
?>
<input type="submit" name="submit" value="Purchase" />
</form>
</body>
</html>
http://pastebin.com/raw.php?i=5CiFprHY
Cheers,
Gitlez
- Anonymous5 years ago
Looks more like an advertisement rather than a question. I decline your offer, though.