Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function buildings() {
- global $database;
- global $player;
- global $self_link;
- // Fetch buildings
- $result = $database->query("SELECT * FROM buildings");
- $buildings = array();
- while($building = $database->fetch($result)) {
- $buildings[$building['id']] = $building;
- }
- if(!empty($_POST['build'])) {
- $building_id = (int)$_POST['building_id'];
- $amount = $_POST['amount'];
- try {
- if($player->money < $buildings[$building_id]['cost']) {
- throw new Exception("You do not have enough money to build this!");
- }
- // Purchase technique
- $player->money -= $buildings[$building_id]['cost'] * $amount;
- $database->query("INSERT INTO player_buildings (owner_id, name, power_use, life, att_inf, att_veh, att_air, att_sea)
- VALUES ('$_SESSION[user_id]', '$buildings[name]', '$power_use', '$life', '$att_inf', '$att_veh', '$att_air', '$att_sea')");
- $player->update();
- echo "Debugg: Buildings have been added.... I hope..";
- } catch (Exception $e) {
- echo $e->getMessage();
- }
- }
- // Display form
- echo "<table style='width:900px;'>
- <tr>
- <th style='width:40% text-align:left;'>Name</th>
- <th style='width:50%;'>Description</th>
- <th style='width:5%;'>Price</th>
- <th style='width:5%;'>Power Usage</th>
- <th style='width:5%;'> </th>
- </tr>";
- foreach($buildings as $id => $building) {
- echo "<tr>
- <td>{$building['name']}</td>
- <td>{$building['description']}</td>
- <td>{$building['cost']}</td>
- <td>{$building['power_use']}</td>
- <td>
- <form action='$self_link' method='POST'>
- <input type='hidden' name='building_id' value='$id' />
- <input style='width:40px' type='number' name='amount' value='amount' />
- <input type='submit' name='build' value='Build' />
- </form>
- </td>
- </tr>";
- }
- echo "</table>";
- }
- $buildings[$building['id']] = $building;
- ^^^^^^^^^^^^^^^
- VALUES ('$_SESSION[user_id]', '$buildings[name]', '$power_[..snip..]
- ^^^^
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement