Kryllster Posted May 12, 2007 Share Posted May 12, 2007 Im at a point now with my game that I need to ustilize a bank and the first thing I want to be able to do is deposit some money and items in a numerical format. Here is the code I have so far!! // Define Account Form Variables $dep_gold = $_POST['dep_gold']; $dep_diamond = $_POST['dep_diamond']; $dep_rubie = $_POST['dep_rubie']; $take_gold = $_POST['take_gold']; $take_diamond = $_POST['take_diamond']; $take_rubie = $_POST['take_rubie']; // Connect to Database include ('config.php'); $uname = $_SESSION['uname']; // Select data from database $sql="SELECT * FROM $tbl_name WHERE uname='$uname'"; $result=mysql_query($sql); // Put info into array Hopefully while($row=mysql_fetch_assoc($result)) { $sql="UPDATE $tbl_name SET $row['bank']+$dep_gold , $row['dbalance']+$dep_diamond , $row['rbalance']+$dep_rubie WHERE uname='$uname'"; //echo $row['bank']; // $row['bank'] = $row['bank'] - '$take_gold'; // $row['dbalance'] = $row['dbalance'] - '$take_diamond'; ///$row['rbalance'] = $row['rbalance'] - '$take_rubie'; mysql_close(); } It's a bit messy I know but Im relatively new and not sure how to do simple arithmetic and appending or updating mysql with the new data. Thanks in Advance, Kryllster Quote Link to comment https://forums.phpfreaks.com/topic/51033-solved-need-help-with-game-code/ Share on other sites More sharing options...
Barand Posted May 12, 2007 Share Posted May 12, 2007 Something like this , assuming $tbl_name is defined somewhere <?php $dep_gold = $_POST['dep_gold']; $dep_diamond = $_POST['dep_diamond']; $dep_rubie = $_POST['dep_rubie']; $take_gold = $_POST['take_gold']; $take_diamond = $_POST['take_diamond']; $take_rubie = $_POST['take_rubie']; // Connect to Database include ('config.php'); $uname = $_SESSION['uname']; // update database $sql="UPDATE $tbl_name SET bank = bank + $dep_gold - $take_gold , dbalance = dbalance + $dep_diamond - $take_diamond , rbalance = rbalance + $dep_rubie - $take_rubie WHERE uname='$uname'"; mysql_query($sql) or die (mysql_error()."<p>$sql</p>"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/51033-solved-need-help-with-game-code/#findComment-251231 Share on other sites More sharing options...
Kryllster Posted May 13, 2007 Author Share Posted May 13, 2007 Thanks for your help, I tried the code it didn't work as it is and I also tried changing some of it in a way that I thought might work still it doesn't update the fields. The table name is in the config.php so I'm not sure where to go from here. I have tried the mysql site but I really have a tough time sorting that out. 1 thing i thought of that might help would be to let you know that I'm using InnoDB if that would make any difference??? Quote Link to comment https://forums.phpfreaks.com/topic/51033-solved-need-help-with-game-code/#findComment-252189 Share on other sites More sharing options...
Barand Posted May 13, 2007 Share Posted May 13, 2007 Did you get an error message? Are you sure $uname contains a correct value? Are you calling session_start()? Quote Link to comment https://forums.phpfreaks.com/topic/51033-solved-need-help-with-game-code/#findComment-252198 Share on other sites More sharing options...
Kryllster Posted May 13, 2007 Author Share Posted May 13, 2007 That did the, session_start() did the trick. Thanks a lot I had to make adjustments as trying to perform a deposit and withdrawal at the same time didn't want to work but this worked out really well in the end and I learned something new! Again Thanks!! Quote Link to comment https://forums.phpfreaks.com/topic/51033-solved-need-help-with-game-code/#findComment-252433 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.