How to Build a PHP Auction Website


Auctions have become extremely popular on the Web, and for good reason. Auction sites allow sellers to connect with a huge number of potential buyers. Building an auction site in PHP can speed your development-to-deployment cycle, but it does require knowledge of PHP as well as relational databases. Knowledge of OOP (object oriented programming) and patterns such as the MVC pattern (model-view-controller) will be of benefit too. In addition, familiarity with HTML, CSS and JavaScript will allow you to shape the look and feel of your site. To concentrate on the specifics of an auction site, we'll assume that your software is installed and configured so that you're ready to develop your site.

Things You'll Need

  • LAMP stack: OS (Linux, Windows, Mac OS X), Web server (Apache, IIS), MySQL, PHP 5
  • At a minimum, you'll want to create the following tables with the included fields: Items (title, description, reserve price, photo, id); Users (name, password, email address, credit card info type and number, shipping address); Bids (amount, item_id, bidder_email_id). These need not be created all at once. For example, you may want to create an Items table, populate it with sample data, and then develop the user interface to resolve any problems that arise.

  • Populate your tables with sample data. You can do this at the myself prompt, but a better way is to use a database wrapper such as PEAR DB (library of database functions) that will provide you access to basic create, read, modify and delete functions that any system needs. That functionality will enable an administrator to add, modify and delete items as needed.

  • Display your data. Initially, you'll probably want to show all items to viewers of your site. Later, you can constrain items by assigning them to a category. Best practice emphasizes isolating functionality from presentation and you'll do this by creating a controller (index.php) that will contain the logic for handling actions (registering a new user, authenticating users, accepting a bid) that you want to provide.

  • The presentational aspects of the site will be handled by a view template, which will contain the HTML and CSS that determines, for example, the properties of each item (color, font, size) as well as its position on the page. This template will be invoked by the controller as needed.

  • Create the bid logic. When users bid on an item, check that they're authenticated and that their bid is higher than the last accepted bid (or reserve, if there are no bids). If so, store their bid in the bids table.

Promoted By Zergnet


You May Also Like

Related Searches

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!