当多个用户调用相同的函数时,在php中只更新一次mysql记录

I have a php auction bid script, the problem is when the bid get over the script makes an ajax call and update all the users bid at once. What is happening is if two users simultaneously opened the page and the auction is over the piece of code runs twice which makes the data corrupted.

Is there any way to prevent this problem ?

Add a timestamp and use the time differences to tell with the bidding is done basis on the start time and duration of the bidding war. This way if users bid after the bidding has ended you pick the closest that didn't go over or whatever your rules say to do.