Jump to content

A bidding system with PHP and MySQL


phil321

Recommended Posts

Hello there,

I have a number of products which I would like to auction off on my site. I would like to get it so that when a customer clicks on a product, they are given the oppurtunity to make a bid for it, right up until the last minute of the auction. I have some PHP and MySQL experience, but is it appropriate to design a script that retrieves the current high bid from a database and allows the customer to enter their email address and a new bid? The script then simply checks if the bid is higher, and if so, sets the new high bid and email address of the new high bidder. What about multiple people trying to bid at the same time - would it be stable (for example, in the last few minutes of the auction)?

Or is this something I should rather find a pre-made script to do?

Thanks for your time and help!
Link to comment
Share on other sites

So long as the condition is part of the update query that the new bid must be greater than the current one, then you should be fine. When MySQL goes to update the data it should briefly lock the data. All db systems do this. So then it will very quickly check that the bid is higher and update the bid and email fields. If it turns out that another bid has come in first then it will be apparent either in the fact that the query didn't do what was intended, and so the current bid is now higher what the user had attempted to enter, or you can check mysql_affected_rows to see if it worked.

Sam.
Link to comment
Share on other sites

example only

<?

$new_amount=($_POST['new_amount']);


$current_amount=($_POST['curent_amount']);


$current_amount="200"; // from the database


$new_amount="400"; // the user input new bid from a form under new_amount.

if($new_amount > $current_amount) {


$query="update bids set $current_amonut where id='$id'":


$result=mysql_query($query);


}else if ($new_amount < $current_amount) {


echo " sorry your bid was lower then the current bid please try agin"

}else{

echo "Thank you  $user your bid is at the top!";

}

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