Home arrow MySQL arrow Page 2 - Building a Simple Affiliate System in PHP/MySQL

Building The Database - MySQL

Setting up an affiliate system on your website can be very lucrative. While there are a lot of details involved, it need not be overly complicated. This article walks you through the steps of creating and setting up a basic affiliate system.

TABLE OF CONTENTS:
  1. Building a Simple Affiliate System in PHP/MySQL
  2. Building The Database
  3. Being Common
  4. Your Index Page
  5. Letting Affiliates Log in
  6. Adding Affiliate Code to Your Site
By: Roger Stringer
Rating: starstarstarstarstar / 58
November 10, 2005

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

First, we want to build the database. This is a pretty basic database designed to keep track of affiliates and their traffic/sales to your website. We'll need two tables.

CREATE TABLE affiliates (
 ID int(10) NOT NULL auto_increment,
 username varchar(50) NOT NULL default '',
 password varchar(32) NOT NULL default '',
 site varchar(255) NOT NULL default '',
 email varchar(255) NOT NULL default '',
 akey varchar(32) NOT NULL default '',
 ptype varchar(32) NOT NULL default '0',
 pemail varchar(255) NOT NULL default '',
 address text NOT NULL,
 PRIMARY KEY  (ID),
 UNIQUE KEY akey (akey)
) TYPE=MyISAM AUTO_INCREMENT=1;

CREATE TABLE affstats (
 ID int(10) NOT NULL auto_increment,
 akey varchar(32) NOT NULL default '',
 type tinyint(4) NOT NULL default '0',
 status tinyint(4) NOT NULL default '0',
 ip varchar(150) NOT NULL default '',
 date datetime NOT NULL,
 OrderID varchar(32) NOT NULL default '',
 price varchar(32) NOT NULL default '',
 PRIMARY KEY  (ID)
) TYPE=MyISAM AUTO_INCREMENT=1;

Setting Your Settings

Your settings will be stored in a file called "config.php." We'll keep this simple.

<?
 $sitename    = ""; // site name
 $siteurl     = ""; // site url
 $redirecturl = ""; // redirect url
 $affpay      = ""; // affiliate payout amount
 $aduser      = ""; // admin username
 $adpass      = ""; // admin password
 $dbhost      = ""; // database hostname
 $dbuser      = ""; // database username
 $dbpassword  = ""; // database password
 $dbname      = ""; // database name
?>

These settings are important and should be set before we start. The variables are broken down as follows:

  $sitename    = The name of your website
  $siteurl     = The URL to the affiliate script as it is
                 installed on your site
  $redirecturl = The URL where visitors are redirected to after
                 coming to your site using an affiliate link.
  $affpay      = The amount affiliates are paid for each sale.
                 If you set it to 5.00, then affiliates
                 will get paid 5.00 for each sale.
  $aduser      = Your management login username
  $adpass      = Your management login password
  $dbhost      = Your database host (usually localhost)
  $dbuser      = Your database username
  $dbpassword  = Your database password
  $dbname      = The name of your database



 
 
>>> More MySQL Articles          >>> More By Roger Stringer
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

MYSQL ARTICLES

- Oracle Unveils MySQL 5.6
- MySQL Vulnerabilities Threaten Databases
- MySQL Cloud Options Expand with Google Cloud...
- MySQL 5.6 Prepped to Handle Demanding Web Use
- ScaleBase Service Virtualizes MySQL Databases
- Oracle Unveils MySQL Conversion Tools
- Akiban Opens Database Software for MySQL Use...
- Oracle Fixes MySQL Bug
- MySQL Databases Vulnerable to Password Hack
- MySQL: Overview of the ALTER TABLE Statement
- MySQL: How to Use the GRANT Statement
- MySQL: Creating, Listing, and Removing Datab...
- MySQL: Create, Show, and Describe Database T...
- MySQL Data and Table Types
- McAfee Releases Audit Plugin for MySQL Users

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: