liamloveslearning Posted June 27, 2011 Share Posted June 27, 2011 Hi, Im about to start building a referral system for my website only im struggling to get my head around the theory first, my website is credit based so for every user you get signed up you receive X credits... I plan on the following... Say user X has the referral link http://www.mysite.com/referral.php?ref=123 When somebody visits referral.php, a query is run and adds 10 credits to the user whose ref = 123. My only problem is I need it to only run the query if they visit the referral link, and then regsiter. Sorry if this is confusing, any input would be great, thanks Quote Link to comment https://forums.phpfreaks.com/topic/240562-referral-system/ Share on other sites More sharing options...
Alfa9 Posted June 27, 2011 Share Posted June 27, 2011 This is just basic, you're gonna have to change it a bit if(isset($_GET['ref'])){ // if the ref variable is set $ref = $_GET['ref']; $query = mysql_query("UPDATE `table` SET `credit` = `credit` + 10 WHERE `ref` = '$ref'"); if (mysql_num_rows($query) !== false){ //ok, done, now display the register form off yours }else{ echo 'An error Has just eccured, try again later '; } } Like I said earlier, this is just a basic example and non secure you'll have to make some changes Quote Link to comment https://forums.phpfreaks.com/topic/240562-referral-system/#findComment-1235672 Share on other sites More sharing options...
liamloveslearning Posted June 27, 2011 Author Share Posted June 27, 2011 Thanks Alfa, I already have something like that, the process needs to happen after the user has registered however; Im thinking after they register they can be passed to a similar page where the query happens Quote Link to comment https://forums.phpfreaks.com/topic/240562-referral-system/#findComment-1235675 Share on other sites More sharing options...
WebStyles Posted June 27, 2011 Share Posted June 27, 2011 grab $_GET['ref'] and keep it in a $_SESSION variable, then if they register, update their points. Quote Link to comment https://forums.phpfreaks.com/topic/240562-referral-system/#findComment-1235676 Share on other sites More sharing options...
jcbones Posted June 27, 2011 Share Posted June 27, 2011 A couple of notes. 1. You need to limit it somehow, so that one person cannot sign up a bunch of accounts under one user. 2. I would set up a trigger that occurred AFTER the registration process, that would add the credit to the user. That would save from a user getting credits on referrals that didn't complete the process. Mysql Trigger Quote Link to comment https://forums.phpfreaks.com/topic/240562-referral-system/#findComment-1235683 Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 28, 2011 Share Posted June 28, 2011 You should automatically add the points after the user have done registering. <input type="hidden" name="ref" value="<?php echo $_GET['ref']; ?>" /> Quote Link to comment https://forums.phpfreaks.com/topic/240562-referral-system/#findComment-1235726 Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 28, 2011 Share Posted June 28, 2011 In the authentication page, you should add this script <?php if (isset($_POST['ref'])) { $ref = $_POST['ref']; $query = mysql_query("UPDATE `table` SET `credit` = `credit` + 10 WHERE `ref` = '$ref'"); if (mysql_num_rows($query) !== false ) { echo "Thanks for registering. You were referred by" . $ref . ". He will be given 10 credits for it. Be a referral."; } else { echo "Thanks for registering!" } } Quote Link to comment https://forums.phpfreaks.com/topic/240562-referral-system/#findComment-1235761 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.