View Full Version : make gold decrease when people buy wood
12-02-2008, 01:48 AM
weird title i know but didn't know how else to explain this...lol
here's my html code..
<select name="select" id="select">
<form id="form1" name="form1" method="post" action="">
<input type="submit" name="Submit" id="Submit" value="Submit" />
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.
12-02-2008, 01:59 AM
What is you're storage type and schema in use?
12-02-2008, 02:05 AM
my storage type is using a database using mySQL and what do you mean by schema ?
12-02-2008, 02:16 AM
How is you're database set up to store this information?
Oh, and do you have any php code to post?
12-02-2008, 02:19 AM
my database isn't setup at all to store the data yet, and no i don't have any php code but i do have the HTML form as you can see..
12-02-2008, 02:24 AM
i just want users to choose a number from the drop down list and click submit and the gold decreases and the wood count goes up by whatever number they chose.
12-02-2008, 02:30 AM
HTML is useless by itself when it comes to processing. You'll need to design you're database first otherwise you can't track any changes.
Essentially, this is what you'll need to do:
float cost <- product (cost, quantity)
array user <-& SELECT FROM STORAGE FOR USER
if user.gold >= cost then
user.gold -= cost
user.wood += quantity
UPDATE FROM STORAGE FOR USER < user.*
Something like this. Just pseudo code, but without a database design I can't provide you with any usable code.
12-02-2008, 02:37 AM
ok sir i have a database!
it has three fields
1. player name
the type of each one is varchar(12)
12-02-2008, 03:15 AM
I would probably make those fields numerical, either int or decimal depending on if you need to track a decimal point or not.
How are you tracking you're users? Through sessions? You'll need to be able to track who you're updating as well. So you'll need an authentication system in the long run too.
I'll assume you're [planning on ]using sessions for this.
$con = mysql_connect('host', 'user', 'pass') or die(mysql_error());
$who = $_SESSION['playername'];
$obCurUser = mysql_query('SELECT * FROM yourplayertable WHERE playername = \'' . mysql_real_escape_string($who) . '\'') or die('Unable to query: ' . mysql_error());
if (mysql_num_rows($obCurUser) == 1)
$aRecord = mysql_fetch_assoc($obCurUser);
$fWoodCost = yourpriceforwood;
$iQuantity = (int)$_POST['select'];
$fCost = $fWoodCost * $iQuantity;
if ($aRecord['gold'] >= $fCost)
mysql_query('UPDATE yourplayertable SET gold = gold - ' . $fCost . ', wood = wood + ' . $iQuantity . ' WHERE playername = \'' . $aRecord['playername'] . '\'') or die('Cannot update: ' . mysql_error());
print 'Successfully purchased ' . $iQuantity . ' wood.';
print 'You do not have the gold to purchase ' . $iQuantity . ' wood.';
print 'No user found.';
Something like this.
It would be a lot better for you to seek a tutorial on PHP and MySQL integration and PHP session handling. Learning to do what you need to do means you'll be able to alter it when you need to.
12-02-2008, 07:44 PM
i'll try to work with something like that!
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.