Web Development Network  |  Sites:    Capital Tutorials    Internet Marketing Books    Arcade Games
Depiction- Webmaster Resources
Stock Image


Contributors: SSD VPS in Europe  |  SEO Las Vegas |  EsqRank

Dental SEO Marketing  |  Best Las Vegas SEO Company  |  Currency Converter Live

Misc Links: Submit Tutorials (Earn $$) l Advertising l Privacy Policy | Site Map

Tutorials > PHP > Affiliate System


 

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:
------------------------------------------------------------------------

<?php           
// include the connect.php
include "connect.php";
// add affiliate
$go = $_POST['add']; 
if ($go)
    {                 
        // if the form is submitted, then process it
        // htmlspecialchars strips html, and addslashes cancels out quotes
        // get all the variables from the form
        $name = htmlspecialchars(addslashes($_POST['name']));         
        $url = htmlspecialchars(addslashes($_POST['url']));
        $image = htmlspecialchars(addslashes($_POST['image']));
        $email = htmlspecialchars(addslashes($_POST['email']));
        
        // insert the info into the database
        mysql_query("INSERT INTO `affiliates` (`name`,`banner`,`url`,`email`,`active`) VALUES ('$name','$image','$url','$email','0');") or die("Insert Query Failed");
        // query worked, tell user
        echo "Your affiliate request has been submitted, but must be approved before it will show up on this site. You will recieve an email once you are accepted.";
    }
else 
    {
        // if the form wasnt submitted 
        // show the form
        echo "<form action='' method='post'>
        Your Name: <input type='text' name='name' /><br />
        Your Email: <input type='text' name='email' /><br />
        Site URL: <input type='text' name='url' /><br />
        Affiliate Image: <input type='text' name='image' /><br />
        <input type='submit' name='add' value='Apply' />";
    }
?>

Tutorial continues on page 2.


 
 

Affiliates

Tutorial Kit Photoshop Tutorials
Tutorial Man Wallpaper Stock  More

Resources