Jump to content

Php Referral System


wadboram
 Share

Recommended Posts

I want to add a referral system to my membership site that saves cookies.Where the steps go like this: Registration>>Member info. entered in database, and referral link given out like mysite.com/ref.php?id=xxx>>Page has sql/php coding which then adds +1 in the users referral row. I found this code

<?phpinclude("connect.php"); //make sure we connect to the database first $user = $_GET['user']; if(!$user){//echo out site normally} else {$sql = mysql_query("SELECT * FROM members WHERE user='$user' LIMIT 1");$row = mysql_fetch_array($sql);$referal = $row['users_referals']; //Get whats in that field$referaladd = $referal +1; //I am not sure on this as ive not used math operators in php before, but basically your adding one onto whats in the db$add = mysql_query("UPDATE members SET users_referals = '$referaladd' WHERE user = '$user'"); //Update the db with the users referalsecho "You were refered by $user";//echo out rest of the site}?>

Does this help?

Link to comment
Share on other sites

I am not to sure, what you're asking or what the problem is, however, for incrementing the referral, you don't need to do this.$referaladd = $referal +1;Its generally, easy to use the shorthand version, (and may be more effcient, don't quote me, I am not sure on that) to do this.$referal+=1; Which basically, says get the value of $referal and increment 1 to it.

Link to comment
Share on other sites

Simple as this, if this is what you're looking for, without knowing too much about you're design implementations or goals.

//To set the cookie you need.if($referal) {	setcookie('referal', 'REFERER');}//To retrieve the saved cookieif($_COOKIE['referal']) {	$referedBy = $_COOKIE['referal'];}

Edited by Gex
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...