Eric Nagel

Eric Nagel

CTO, PHP Programmer, Affiliate Marketer & IT Consultant

Building a Datafeed Site – Step 1b

I have been, or can be if you click on a link and make a purchase, compensated via a cash payment, gift, or something else of value for writing this post. Regardless, I only recommend products or services I use personally and believe will be good for my readers.

The next step in building a datafeed website is getting the data into the database, but to do this, we need to build an administrative section to your website, and add some helper functions & files.

vars.php was a file seen in Step 1, which I use to store the mysql connection and other variables. Here’s a simplified version of the one I’m using:

<?php
	// MySQL
	$DB_NAME = 'your_db_name';
	$DB_USER = 'your_db_username';
	$DB_PASSWORD = 'your_db_password';
	$DB_HOST = 'your_db_host';

	mysql_connect($DB_HOST, $DB_USER, $DB_PASSWORD);
	mysql_select_db($DB_NAME);

	// Your ShareASale ID
	$nSASID = 132296;

	// Shortcut / Alias
	function myres($cString) {
		return mysql_real_escape_string(stripslashes($cString));
	} // ends function mres($cString)
?>

Change lines 3-6 and 12.

Next, you’ll need to set-up an admin.php page, like so:

<?php
	include('./vars.php');
	include('./admin-password.php');
	$bNavHome = true;
	include('./header.php');
?>
			<div class="post">
				<h2 class="title">GreenWhiteAndBlackTea.com Admin</h2>
				<div class="entry">
					<ul>
						<li><a href="admin-sas-datafeed.php">Upload ShareASale Datafeed</a></li>
					</ul>
				</div>
			</div><!-- ends class="post" -->
<?php
	include('./footer.php');
?>

Change as necessary – this is just an index for your admin section.

and admin-password.php:

<?php
if (!$_SERVER['PHP_AUTH_USER']) {
        Header("WWW-authenticate: basic realm=\"" . $_SERVER['HTTP_HOST'] . " Admin\"");
        Header("HTTP/1.0 401 Unauthorized");
        exit;
}
else {
        if (($_SERVER['PHP_AUTH_USER'] == 'the-username-you-want')
        && ($_SERVER['PHP_AUTH_PW'] == 'ssssshhhhh-super-secret')) {
                // OK!!!!
				$_SESSION['bAdmin'] = true;
                ;
        }
        else {
                Header("WWW-authenticate: basic realm=\"" . $_SERVER['HTTP_HOST'] . " Admin\"");
                Header("HTTP/1.0 401 Unauthorized");
                echo("Login failed.\n");
                exit;
        }
}
?>

Set your username & password that you’d like on lines 8 & 9

Finally, in your MySQL database, create the products table:

CREATE TABLE `products` (
  `ProductID` int(10) unsigned NOT NULL,
  `Name` varchar(255) NOT NULL,
  `MerchantID` int(10) unsigned NOT NULL,
  `Merchant` varchar(255) NOT NULL,
  `Link` varchar(255) NOT NULL,
  `Thumbnail` varchar(255) NOT NULL,
  `BigImage` varchar(255) NOT NULL,
  `Price` float(8,2) unsigned NOT NULL,
  `RetailPrice` float(8,2) unsigned NOT NULL,
  `Category` varchar(50) NOT NULL,
  `Subcategory` varchar(50) NOT NULL,
  `Description` text NOT NULL,
  `Custom1` varchar(255) NOT NULL,
  `Custom2` varchar(255) NOT NULL,
  `Custom3` varchar(255) NOT NULL,
  `Custom4` varchar(255) NOT NULL,
  `Custom5` varchar(255) NOT NULL,
  `Lastupdated` datetime NOT NULL,
  `Status` varchar(50) NOT NULL,
  `Manufacturer` varchar(255) NOT NULL,
  `PartNumber` varchar(255) NOT NULL,
  `MerchantCategory` varchar(255) NOT NULL,
  `MerchantSubcategory` varchar(255) NOT NULL,
  `ShortDescription` varchar(255) NOT NULL,
  `ISBN` varchar(25) NOT NULL,
  `UPC` varchar(25) NOT NULL,
  `SKU` varchar(255) NOT NULL,
  `CrossSell` varchar(255) NOT NULL,
  `MerchantGroup` varchar(255) NOT NULL,
  `MerchantSubgroup` varchar(255) NOT NULL,
  `CompatibleWith` varchar(255) NOT NULL,
  `CompareTo` varchar(255) NOT NULL,
  `QuantityDiscount` varchar(255) NOT NULL,
  `Bestseller` tinyint(1) unsigned NOT NULL,
  `AddToCartURL` varchar(255) NOT NULL,
  `ReviewsRSSURL` varchar(255) NOT NULL,
  `Option1` varchar(255) NOT NULL,
  `Option2` varchar(255) NOT NULL,
  `Option3` varchar(255) NOT NULL,
  `Option4` varchar(255) NOT NULL,
  `Option5` varchar(255) NOT NULL,
  `bActiveProduct` tinyint(1) unsigned NOT NULL,
  UNIQUE KEY `ProductID` (`ProductID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

I’m wrapping up the script which loads the data, which will be posted tomorrow.

Datafeed Site Navigation

Comments
  • Trackback: How to Build an Affiliate Datafeed Site Series from an Affiliate - 5 Star Affiliate Blogs
  • Pierre
    Posted November 16, 2011 6:26 pm 0Likes

    Thanks for all answer. I have two questions;
    1- when you create the database, why don’t you put an ID autoincrement as the first element of the product table?
    2- can you give me your opinion about sqlite as the database for datafeed website?
    thanks!

    • Eric Nagel
      Posted November 17, 2011 10:30 am 0Likes

      1 – ProductID is unique, and given by the network. No need for another id

      2 – Nope 🙂 I’ve never used sqlite, sorry

      Eric

  • Trackback: Datafeeds
  • Rick
    Posted August 22, 2012 3:15 pm 0Likes

    Hi, I was following your tutorial but I got stuck in your 1b page. I cannot log into the http://www.mysite.com/admin-sas-datafeed.php page. I already changed the username and password in the admin-password.php file but the page will keep asking me for the username and password over and over. Would you happen to know why? This is what I did:
    1) I changed the username and password of the admin-password.php file which are in lines 8 and 9.
    2) I then uploaded the files that you gave us to my server.
    3) I chmod the temp forlder to 777.
    4) I then logged into the following page http://www.mysite.com/admin-sas-datafeed.php and it asks me for the username and password. I am stuck here, I cannot log into my site. I put the same exact username and password that I used in the admin-password.php file but it does not work.
    I would greatly appreciate it if you may know why I am having problems. Thank you so much in advance.

  • Rick
    Posted August 22, 2012 4:51 pm 0Likes

    How sorry that you delete my question. Your tutorial sucks, you should give more detailed information instead of being lazy and making the reader figure out what is going on.

  • Eric Nagel
    Posted August 22, 2012 8:37 pm 0Likes

    Sorry to disappoint you with this free information, Rick. You can always buy datafeedr if you don’t want to learn how to do this yourself. Or hire me.

Leave A Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.