Jump to content

Double Submit


StormTheGates

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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