Advertisement
gitlez

Untitled

Jun 25th, 2011
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.13 KB | None | 0 0
  1. <?php
  2.  
  3. $cash = 20000000;
  4. $factories = Array(
  5.     '1' => 12000000,
  6.     '2' => 18000000,
  7.     '3' => 24000000
  8. );
  9. if(strlen($_POST['submit']) > 0){
  10.     $factoryCost = $factories[$_POST['factory']];
  11.     if ($cash >= $factoryCost){
  12.         $cash -= $factoryCost;
  13.         echo "You have successfully built factory #" . $_POST['factory'] . '<br />';
  14.         echo 'You have $' . number_format($cash) . ' remaining.<hr />';
  15.     }else{
  16.         echo 'You do not have sufficient funds. <span style="color: #900;">$' . number_format($cash - $factoryCost) . '</span><hr />';
  17.     }
  18. }
  19.  
  20. ?>
  21. <html>
  22.     <head>
  23.         <title>Factory Purchasing</title>
  24.     </head>
  25. <body>
  26.     <form method="POST">
  27.         You Currently have $<?php echo number_format($cash); ?> in the bank.<br />
  28.         Select Factory to purchase:<br />
  29.         <?php
  30.             foreach($factories as $num=>$cost){
  31.                 echo '<input type="radio" name="factory" value="' . $num . '" />#' . $num . ' ($' . number_format($cost) . ')<br />';
  32.             }
  33.        
  34.         ?>
  35.         <input type="submit" name="submit" value="Purchase" />
  36.     </form>
  37. </body>
  38. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement