mandukar Posted January 23, 2007 Share Posted January 23, 2007 hi I'm very new with php but understand most of the basics..i'm in abit of a headace mode atm, and was wondering if someone could help me..I am trying to enable players to tranfer money from there bank to another players bank. I have been able to get it so that it'll take money from the player but the other player doesn't get it.heres a copy of the script..any help will be most greatful from mandukar.<? <ul> <li><a href=donate.php?view=donate>Donations</a> </ul><? if ($view == donate) { print "Please donate to a player, and help it out financially."; print "<form method=post action=donate.php?view=donate&step2=donate>"; print "Donate <input type=text size=5 name=amount value=0> <select name=type><option value=credits>Credits</option><option value=platinum>Platinum</option></select> <input type=text name=aid> as an <select name=donate> to player. <input type=submit value=Donate>"; print "</form>"; if ($step2 == donate) { if ($amount > $stat[$type]) { print "You don't have enough $type."; } else { mysql_query("update players set $type=$type-$amount where id=$stat[id]"); print "You donated <b>$amount $type</b> to the player."; mysql_query("update players set credits='$bank' where id=$aid"); } } }?> Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted January 23, 2007 Share Posted January 23, 2007 [code] <ul> <li><a href=donate.php?view=donate>Donations[/url] </ul><?php if ($view == donate) { print "Please donate to a player, and help it out financially."; print "<form method=post action=donate.php?view=donate&step2=donate>"; print "Donate <input type=text size=5 name=amount value=0> <select name=type><option value=credits>Credits</option><option value=platinum>Platinum</option></select> <input type=text name=aid> as an <select name=donate> to player. <input name =donate_to type=submit value=Donate>"; print "</form>"; if ($step2 == donate) { if ($amount > $stat[$type]) { print "You don't have enough $type."; } else { $donate_to = $_POST['donate_to']; mysql_query("update players set $type=$type-$amount where id=$stat[id]"); print "You donated $amount $type to the player."; mysql_query("update players set credits=$bank-$amount where id=$aid"); mysql_query("update players set credits=$bank+$amount where id=$donate_to"); } } }?>[/code]You only had a mysql query updating ONE persons item amount when the item was transferred. You also didn't do your query right...you were updating the persons type with whatever amount was sent/given. You need to update it by adding/subtacting to what they have.For example: If they have $1000 you want to do a query that says update money 1000+amount transferred for the person recieving the money. Quote Link to comment Share on other sites More sharing options...
mandukar Posted January 23, 2007 Author Share Posted January 23, 2007 many thanks i'll let you know if it works Quote Link to comment Share on other sites More sharing options...
mandukar Posted January 23, 2007 Author Share Posted January 23, 2007 it works but it has a - infront of the money, which means its taken it away.. and the player can't spend money. Quote Link to comment Share on other sites More sharing options...
mandukar Posted January 23, 2007 Author Share Posted January 23, 2007 I got it working, the - and + had to be swoped around. many thanks for the help :D Quote Link to comment Share on other sites More sharing options...
mandukar Posted January 23, 2007 Author Share Posted January 23, 2007 another question...how would I go about giving players money out of thin air kind of thing..by using admin.phpgive me a shout if you need the admin script. Quote Link to comment Share on other sites More sharing options...
mandukar Posted January 23, 2007 Author Share Posted January 23, 2007 bumping up. Quote Link to comment Share on other sites More sharing options...
Tandem Posted January 23, 2007 Share Posted January 23, 2007 Just add the money to their total. i.e$give = mysql_query("UPDATE MEMBERS SET CASH=CASH+$amount WHERE USERNAME='$username'"); Quote Link to comment Share on other sites More sharing options...
mandukar Posted January 23, 2007 Author Share Posted January 23, 2007 ok, would that go somthing like...[quote]<? if ($view == Give) { print "tgive some members some money."; print "<form method=post action=admin.php?view=give&step2=give>"; print "Donate <input type=text size=5 name=amount value=0> <select name=type><option value=credits>Credits</option></select> <input type=text name=aid> to player. <input type=submit value=give>"; print "</form>"; if ($step2 == give) { if ($amount > $stat[$type]) { print "You don't have enough $type."; } else { mysql_query("update players set $type=$type-$amount where id=$stat[id]"); print "You donated $amount $type to the player."; $give = mysql_query("UPDATE MEMBERS SET CASH=CASH+$amount WHERE USERNAME='$username'"); } } }?>[/quote] Quote Link to comment Share on other sites More sharing options...
mandukar Posted January 23, 2007 Author Share Posted January 23, 2007 bump Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted January 23, 2007 Share Posted January 23, 2007 I am assuming admin.php is just a feature where you can add money to anyones accounts...so this is what you would do.[code]<?phpif ($_POST['give']){$id = $_POST['id'];$amount = $_POST['amount'];mysql_query("UPDATE users SET money=money+$amount WHERE playerID='$id'");echo "Successfully gave money to player #$id.<p>";}print<<<HERE<form action="admin.php" action="post">Player ID: <input type="text" name="id"><p>Amount to give: $<input type="text" name="amount"><input type="submit" name="give" value="Give Money"></form>HERE;?>[/code]You might have to set the values in the UPDATE query to match your DB rows. Other then that, I hope this is what you are looking for ^^ Quote Link to comment 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.