A walkthrough showing how to create your affiliation system.
Note: This tutorial walkthrough is intended for those who have a solid foundation of PHP basics.
For this tutorial, all code is the full file with comments.
1. Lets start off by creating our table. Put the following code in the SQL box in phpMyAdmin or similar script to create your database.
Code:
------------------------------------------------------------------------
CREATE TABLE `affiliates` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) NOT NULL default '',
`banner` text NOT NULL,
`url` text NOT NULL,
`email` varchar(255) NOT NULL default '',
`in` int(11) NOT NULL default '0',
`out` int(11) NOT NULL default '0',
`active` int(1) NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM;
------------------------------------------------------------------------
2. Now we need to create a config file to store the database access information. (You will need to edit the username and password to your desired setting.)
Code:
------------------------------------------------------------------------
<?php
// connect.php for affiliate system
$host = "localhost"; // default
$user = "username"; // mysql username
$pass = "password"; // mysql password
$db = "database"; //mysql database
@mysql_connect($host,$user,$pass) or die("Could not connect<br />".mysql_error());
@mysql_select_db($db) or die("Could not connect to MySQL database $db");
?>
------------------------------------------------------------------------
3. This is a fairly simple file, all it does is connect to the MySQL database. If the connection fails for any reason, the error will be shown.
Your going to need a page where your site visitors can submit a request to become an affiliate.
Code:
------------------------------------------------------------------------