StormTheGates Posted May 10, 2007 Share Posted May 10, 2007 I made this topic sorta here once before. Basically I am having a problem with my game. I have a bank feature, players can add and withdraw money ect ect. What it seems people are doing is quickly when the server is under a load to add their money to it and buy something at the same time. So the money goes in the bank while they get the item they bought as well. Is there anyway you guys can think of to stop people from submitting 2 forms at the same time? All ideas are welcome. Quote Link to comment https://forums.phpfreaks.com/topic/50867-double-submit/ Share on other sites More sharing options...
Nhoj Posted May 10, 2007 Share Posted May 10, 2007 The best way to do it would be to check the users money just before making the changes in your database. If they don't have as much money as they are trying to use display an error. Quote Link to comment https://forums.phpfreaks.com/topic/50867-double-submit/#findComment-250191 Share on other sites More sharing options...
Wildbug Posted May 10, 2007 Share Posted May 10, 2007 Use transactions. They were made for that kind of thing. (What crafty users you have.) Quote Link to comment https://forums.phpfreaks.com/topic/50867-double-submit/#findComment-250215 Share on other sites More sharing options...
StormTheGates Posted May 11, 2007 Author Share Posted May 11, 2007 Transactions? Quote Link to comment https://forums.phpfreaks.com/topic/50867-double-submit/#findComment-250221 Share on other sites More sharing options...
Wildbug Posted May 11, 2007 Share Posted May 11, 2007 Does your database have a manual? Quote Link to comment https://forums.phpfreaks.com/topic/50867-double-submit/#findComment-250506 Share on other sites More sharing options...
StormTheGates Posted May 11, 2007 Author Share Posted May 11, 2007 Its just mysql. Ive sorta come up with a solution where I set a session called LOCKED to true at the start of the script and then false at the end. That way if they submit one it locks, and then the second runs up against the check to see if its locked. Think this will work? Quote Link to comment https://forums.phpfreaks.com/topic/50867-double-submit/#findComment-250563 Share on other sites More sharing options...
Wildbug Posted May 11, 2007 Share Posted May 11, 2007 Try looking up LOCK TABLES and the related material that will be linked from there to learn about ways to deal with transactions. But to save yourself some work, can you use a multitable, conditional UPDATE? I don't know how your tables are organized, but something like: UPDATE bank_account,items_for_sale SET bank_account.balance=bank_account.balance -items_for_sale.price, items_for_sale.quantity = items_for_sale.quantity - 1 WHERE bank_account.user_id = xx -- (Your user's id here) AND items_for_sale.id = xx -- (Item's id here) AND items_for_sale.quantity > 0 AND bank_account.balance >= items_for_sale.price; Quote Link to comment https://forums.phpfreaks.com/topic/50867-double-submit/#findComment-250658 Share on other sites More sharing options...
chocopi Posted May 11, 2007 Share Posted May 11, 2007 another way you could do it is where the button become locked once the user has clicked on it. i dont know how to do this but i have seen it before somewhere else. so when the user submitted the form the button became locked and changed from submit to submitting... Quote Link to comment https://forums.phpfreaks.com/topic/50867-double-submit/#findComment-250746 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.