Jump to content

Recommended Posts

weird title i know but didn't know how else to explain this...lol

 

here's my html code..

<p>GOLD: 100</p>
<p>WOOD: 0</p>
<p>BUY WOOD:</p>
<p>
  <label>
  <select name="select" id="select">
    <option value="10">10</option>
    <option value="20">20</option>
    <option value="30">30</option>
  </select>
  </label>
</p>
<form id="form1" name="form1" method="post" action="">
  <label>
  <input type="submit" name="Submit" id="Submit" value="Submit" />
  </label>
</form>
<p> </p>

 

I'm trying to make it so when people buy wood there wood count goes up and there gold count goes down....it sounds easy but I'm kind of new to PHP.

<?php
if(isset($_POST['Submit']))
{
    $wood += (int) $_POST['select'];
    $gold = $gold - ($wood / $_POST['select'] *  5);//5 gold per piece?
}
else
{
$gold = 50;
$wood = 0;
}
?>
<p>GOLD: <?php echo $gold;?></p>
<p>WOOD: <?php echo $wood;?></p>
<p>BUY WOOD:</p>
<p>
<form id="form1" name="form1" method="post" action="">
  <label>
  <select name="select" id="select">
    <option value="10">10</option>
    <option value="20">20</option>
    <option value="30">30</option>
  </select>
  </label>
</p>
  <label>
  <input type="submit" name="Submit" id="Submit" value="Submit" />
  </label>
</form>
<p> </p>

Something like that might work, but next time try your self first.

ok i fixed it up a tad and now have this code...

<?php
if(isset($_POST['Submit']))
{
    $wood += (int) $_POST['select'];
    $gold = $gold - ($wood - $_POST['select'] *  10);//5 gold per piece?
}
else
{
$gold = 100;
$wood = 0;
}
?><style type="text/css">
<!--
.style1 {
font-size: 18px;
color: #FF0000;
}
-->
</style>
<p><span class="style1">YOU START OFF WITH 100 GOLD!</span></p>
<p>GOLD: <?php echo $gold;?></p>
<p>WOOD: <?php echo $wood;?></p>
<p>BUY WOOD:</p>
<p>
<form id="form1" name="form1" method="post" action="">
  <label>
  <select name="select" id="select">
    <option value="10">10</option>
    <option value="20">20</option>
    <option value="30">30</option>
  </select>
  </label>
</p>
  <label>
  <input type="submit" name="Submit" id="Submit" value="Submit" />
  </label>
</form>
<p> </p>

 

when i click submit when the thigns on 10 the gold goes down to 90 which is good...but when i choose 20 or 30 it gives the gold a large number...i want it so when i choose 20 the gold goes down by 20 and when i choose 30 the gold goes down by 30 ...i tried and i dont know what to do.. lol

try

<?php
if(isset($_POST['Submit']))
{
$wood += (int) $_POST['select'];
$cost_of_wood = 10;
$amount_of_wood = $_POST['select'];
$cost = $amount_of_wood * $cost_of_wood;
if($cost > $gold)
	echo "Not enough gold";
else
	$gold = $gold - $cost;
}
else
{
$gold = 100;
$wood = 0;
}
?><style type="text/css">
<!--
.style1 {
   font-size: 18px;
   color: #FF0000;
}
-->
</style>
<p><span class="style1">YOU START OFF WITH 100 GOLD!</span></p>
<p>GOLD: <?php echo $gold;?></p>
<p>WOOD: <?php echo $wood;?></p>
<p>BUY WOOD:</p>
<p>
<form id="form1" name="form1" method="post" action="">
  <label>
  <select name="select" id="select">
    <option value="10">10</option>
    <option value="20">20</option>
    <option value="30">30</option>
  </select>
  </label>
</p>
  <label>
  <input type="submit" name="Submit" id="Submit" value="Submit" />
  </label>
</form>
<p> </p>

 

It would be better to use sessions to store the amount of wood and gold though

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.