berry05 Posted December 2, 2008 Share Posted December 2, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/135080-solved-make-gold-decrease-when-people-buy-wood/ Share on other sites More sharing options...
trq Posted December 2, 2008 Share Posted December 2, 2008 Where is your php code? Quote Link to comment https://forums.phpfreaks.com/topic/135080-solved-make-gold-decrease-when-people-buy-wood/#findComment-703616 Share on other sites More sharing options...
awpti Posted December 2, 2008 Share Posted December 2, 2008 He wants us to write it for him. Quote Link to comment https://forums.phpfreaks.com/topic/135080-solved-make-gold-decrease-when-people-buy-wood/#findComment-703654 Share on other sites More sharing options...
DeanWhitehouse Posted December 2, 2008 Share Posted December 2, 2008 <?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. Quote Link to comment https://forums.phpfreaks.com/topic/135080-solved-make-gold-decrease-when-people-buy-wood/#findComment-703655 Share on other sites More sharing options...
berry05 Posted December 2, 2008 Author Share Posted December 2, 2008 yes i was looking for something like that! thxs! i'll work from there Quote Link to comment https://forums.phpfreaks.com/topic/135080-solved-make-gold-decrease-when-people-buy-wood/#findComment-704254 Share on other sites More sharing options...
berry05 Posted December 2, 2008 Author Share Posted December 2, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/135080-solved-make-gold-decrease-when-people-buy-wood/#findComment-704314 Share on other sites More sharing options...
DeanWhitehouse Posted December 2, 2008 Share Posted December 2, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/135080-solved-make-gold-decrease-when-people-buy-wood/#findComment-704329 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.