GMChost.com Webmaster Guide

Home | Searchdomain name registration | free web hosting | shared hosting | Ecommerce | Site Submit | PC2Phone | Voice Email | Voice Chat | Dating Services | Dedicated Hosting | reseller hosting | dedicated hosting | Finding Hosting | Web Hosting Explained | My Account

Webmaster Guide > Create your own affiliate program with paypal

Create your own affiliate program with paypal
by Lalit Goklani

Affiliate program is means of drawing visitors to your website
by paying revenue to the promoter. You can join any third
party marketing organization such as cj.com to take the
administrative and fraud control hassles away from you.
But not all businesses can afford such third party solutions
and need to cut the expenses intially. I am going to discuss
here simple solution of setting up your own affiliate program
with paypal payment gateway using the required PHP as front end,
MySQL database and setting cookies.

Step->1
Create mysql table 'affiliates' using code below:

CREATE TABLE `affiliates` (
`id` tinyint(5) unsigned NOT NULL auto_increment,
`paypal_email` varchar(100) NOT NULL default '',
`affiliate_name` varchar(100) default NULL,
`flag` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`id`),
UNIQUE KEY `paypal_email` (`paypal_email`)
)

PHP Code to create above table save as create_table.php
Replace mydatabase with your database name

<?
$db="mydatabase";
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link)
or die("Select DB Error: ".mysql_error());
//create table
mysql_query("CREATE TABLE `affiliates`(
`id` tinyint(5) unsigned NOT NULL auto_increment,
`paypal_email` varchar(100) NOT NULL default '',
`affiliate_name` varchar(100) default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `paypal_email` (`paypal_email`)
)")or die("Create table Error: ".mysql_error());
mysql_close($link);
?>

Step->2
Create a form for affiliate sign up and also enter these
values into mysql table created above using php.

Step 2 is to build the form document to retrieve affiliate
information. The code below shows a simple html form document
set up to retrieve some personal knowledge about our affiliate
save as form.php.

<html>
<head>
<title>Affiliate Sign Up Page</title>
</head>
<body>

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Your Full Name : <input name="affiliate_name" type="text">
Your Paypal Email : <input name="paypal_email" type="text">
<input type="submit" value="Submit">
</form>

<?php
$affiliate_name=$_POST['affiliate_name'];
$paypal_email=$_POST['paypal_email'];
if (isset($_POST['submit'])) { // if page is not submitted to itself echo the form
$db="mydatabase";
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link)
or die("Select DB Error: ".mysql_error());
mysql_query("INSERT INTO affiliates(affiliate_name,paypal_email) VALUES ('$affiliate_name','$paypal_email')")or die("Create table Error: ".mysql_error());
mysql_close($link);
echo "<center>Your data is submitted successfully and will be contacted on approval along with instructions for our affiliate program</center>";
}
?>
</body>
</html>

Above code generates affiliate id automatically.

Step->3
You need to put following php code on the payment page of
your website or index.php page. Remember below code shall be
placed before any html code and above any other code, the
page shall be the php page.

<?php
$aid = $_GET['aid'];
if(isset($aid)){
setcookie("a_id",$aid,time()+7776000);
}
?>

This will allow affiliates to use your index.php page as
http://www.yourdomain.com/index.php?aid=affiliate id
See it in action at http://www.ezinead.net

Step->4
Contact the affiliate by viewing the data using below code
and save as view_affiliate.php

<?php
$db="mydatabase";
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link)
or die("Select DB Error: ".mysql_error());

$result = mysql_query("select * from affiliates");
if(!$result){
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}

//Use result to generate table for your viewing

while ($row = mysql_fetch_assoc($result)) {
echo "Affiliate ID: $row['id']<br>";
echo "Affiliate_Name:$row['affiliate_name']<br>";
echo "Paypal Email: $row['paypal_email']<br>";
echo "<hr>";
}

mysql_close($link);

?>

Using above code contact the affiliate at their paypal email
and forward them formal instructional letter along with their
affiliate link described in step 3 as
http://www.yourdomain.com/index.php?aid=affiliate id

Step->5
This is final step of setting your affiliate program. Replace
your paypal form with following change save as order.php

<?php

$db="mydatabase";
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link)
or die("Select DB Error: ".mysql_error());

$result = mysql_query("select * from affiliates where id like '$a_id'");
if(!$result){
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}

//Use result to generate paypal form

while ($row = mysql_fetch_assoc($result)) {
$paypal_email = $row['paypal_email];
}
?>

You need to specify the amount $amount you wish to
forward the affiliate for the sale and then modify the
paypal form so that it again send the customer to
complete your payment as well. This can be done using
below code, I am using paypal variables that needs to
be modified with below snippet.

Replace
<input type="hidden" name="business" value="paypal_email">
with below snippet
<input type="hidden" name="business" value="<?php echo $paypal_email ?>">

Use
<input type="hidden" name="return" value="New page created for paying you">
instead of your original return paypal input.

Replace
<input type="hidden" name="amount" value="Your total amount">
as <input type="hidden" name="amount" value="<? echo $amount ?>">
where $amount is the amount paid to affiliate.

With the help of php and mysql we are able to run our affiliate
program for paypal gateway, this program can be extended for
stormpay, ikobo and other payment services that allow pass
through variables.

Example of this snippet as franchise program at
http://www.ezinead.net
http://www.ezineadvertising.biz
http://www.safelist-blaster.net


Lalit Goklani, mailto:lgoklani@yahoo.com a web developer
and runs a hosting company http://www.hostdude.net

This article is reprinted with permission from www.WritingCareer.com

    Chat - free live local phone chat with singles in over 46 cities


Domain Hosting | Dedicated Servers

Copyright © 2004, gmchost.com Web Hosting Guide Domain Name Registration

 All Rights Reserved. sales@gmchost.com