Jump to content

[SOLVED] Need help with game code!!


Kryllster

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/51033-solved-need-help-with-game-code/
Share on other sites

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>");


?>

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???

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!!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.