Jump to content

* * * - - 2 votes

Affiliates CMS Part 1

  • Please log in to reply
3 replies to this topic

#1 nitr0x


    Young Padawan

  • Members
  • Pip
  • 201 posts

Posted 02 May 2007 - 12:52 PM

Part one of a full affiliates system, so what will this affiliates system include?
  • Affiliates Page
  • Number of affiliates
  • Request Affiliate in AJAX
  • Admin: Add affiliate
  • Admin: Delete Affiliate
  • Admin: Accept Affiliate
The Admin panel will come in part 2, but for now, we'll do the rest.

We need four pages set up for this to work first, so in notepad or dreamweaver or something similar, make the following pages.
  • affiliates.php
  • affrequest.php
  • affrequest.js
  • config.php
So first, we need to start with making a table. Below is the SQL for this table.

CREATE TABLE `affiliates` (
`id` INT(11) NOT NULL auto_increment PRIMARY KEY,
`sitename` VARCHAR(30) NOT NULL,
`siteurl` VARCHAR(200) NOT NULL,
`imgurl` VARCHAR(200) NOT NULL,
`email` VARCHAR(70) NOT NULL,
`approved` VARCHAR(3) NOT NULL default'0'

Now onto the pages... Read through the code, they include comments, comments are marked with a // infront of it.


function makeInstance() {var http_request = false;//This fuctions will try an XML request which is for mozilla, safari, etc. If it can't do it then an activeX request which is for IE, this let's AJAX work.if (window.XMLHttpRequest) { // Mozilla, Safari,...http_request = new XMLHttpRequest();} else if (window.ActiveXObject) { // IEtry {http_request = new ActiveXObject("Msxml2.XMLHTTP");} catch (e) {try {http_request = new ActiveXObject("Microsoft.XMLHTTP");} catch (e) {}}}if (!http_request) {alert('Giving up <img src='http://www.pixel2life.com/forums/public/style_emoticons/<#EMO_DIR#>/sad.gif' class='bbc_emoticon' alt=':)' /> Cannot create an XMLHTTP instance');return false;}//If we can't make it, then we say we can't and stop.return http_request;}ajax = makeInstance();function requestaff() {var affname = document.getElementById("affname").value;var affurl = document.getElementById("affurl").value;var affimg = document.getElementById("affimg").value;var affemail = document.getElementById("affemail").value;var affcode = document.getElementById("affcode").value;var affcodeh = document.getElementById("affcodeh").value;//Above we make all the fields into javascript variables to use later.ajax.onreadystatechange = handleResponse; //Is the page ready?ajax.open('POST', 'http://www.domain.com/affrequest.php', true);//Above we open up our page, which needs to be a full url in POST method.ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');//Set header type as a form.ajax.send('affname=' + affname + '&affurl=' + affurl + '&affimg=' + affimg + '&addemail=' + affemail + '&affcode=' + affcode + '&affcodeh=' + affcodeh);//Above we send the variables in the url as post method.}function handleResponse() {if(ajax.readyState < 4) {document.getElementById("are").innerHTML = "Transferring Data...";//Is the page ready? If not, put in transferring data on the page.}if(ajax.readyState == 4) {if(ajax.status == 200) {document.getElementById("are").innerHTML = ajax.responseText;} else {document.getElementById("are").innerHTML = ajax.status;}}}


Well that concludes part 1, you can actually have your system like this, since you can control everything in the database center such as PHPMyAdmin.

#2 Tarquin


    Young Padawan

  • Members
  • Pip
  • 67 posts
  • Gender:Male
  • Location:London
  • Interests:I'm a huge Crystal Palace fan (Soccer team in England for you Americans)

Posted 04 June 2007 - 04:36 PM

Unless it just me, I think you should seriously consider test what you have just done.

#3 Smashe


    Young Padawan

  • Members
  • Pip
  • 18 posts
  • Gender:Male
  • Location:England

Posted 16 June 2008 - 10:17 AM

Yikes, maybe you should test it for example;

&lt;script src="affrequest.js" type="text/javascript"></script>

&lt; - you mean "<"

Also why would you want to submit UPPERCASE username and password credentials to the database ?

#4 Arsenal19


    Young Padawan

  • Members
  • Pip
  • 41 posts

Posted 19 July 2008 - 02:28 PM

Another thing, you should consider doing is when writing comments in code as a major part of your tutorial is keeping the number of characters per line considerably down. On thing that turns people away is having to scroll side ways to read comments in your code. I try to keep my comments to 50-60 characters a line.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users