Eric Nagel

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