Sigurd Posted June 8, 2011 Share Posted June 8, 2011 Greetings, I am willing to add a simple referral system to a exchange script I've downloaded. The aim is to the user give his link like site.com/index.php?ref=123 and by the moment someone click his link it generates a cookie, when they register he gets 500 credits. I tried splitting into 2 files and using include, but it wont credit. The two pieces of script I have to do that are the cookies: <?PHP $ref = ($_GET['ref']); setcookie ('referred-user', $ref, time()+36000); ?> and the credits insertion into database: <?PHP mysql_connect('localhost', 'root', '') or die ("Database CONNECT Error (line 32)"); $ref = $_COOKIE['referred-user']; dq("update banex set i_earned = i_earned + 500 where number = '$ref'",1); ?> "number" is a unique auto inc id wich I used in here to refer to the referrer. I do not have a register page and register successful page separated, they are all bounded into one single index, which contains the templates in html. index is this one: <?PHP include('./functions.php'); if (!$_POST) page_from_template('join.html',$s); include('./ref.php'); $in = $_POST; if ((!$in[urlbanner]) OR (!$in[username]) OR (!$in[password]) OR (!$in) OR (!$in[siteurl])) public_problem('All fields are required. Please try again.'); if (!eregi("^[a-z0-9]{5,15}$",$in[username])) public_problem('Incorrect username. It should contain only letters and numbers and have 5-15 characters.'); if (!eregi("^[a-z0-9]{5,15}$",$in[password])) public_problem('Incorrect password. It should contain only letters and numbers and have 5-15 characters.'); if (strlen($in) > 255) public_problem('Email address is too long. Maximum is 255 characters.'); if (strlen($in[siteurl]) > 255) public_problem ('URL is too long. Maximum is 255 characters.'); if (strlen($in[urlbanner]) > 255) public_problem ('Banner URL is too long. Maximum is 255 characters.'); if (!check_email($in)) public_problem ('Wrong email address. Please try again.'); if (!eregi("http://*",$in[siteurl])) public_problem ('Wrong URL. Please try again.'); $q = dq("select count(*) from $s[tblname] where username = '$in[username]'",0); $data = mysql_fetch_row($q); if ($data[0]) public_problem('Entered username is already in use. Please use another.'); eregi(".*gif$",$in[urlbanner],$hh); eregi(".*jpg$",$in[urlbanner],$hh); eregi(".*png$",$in[urlbanner],$hh); if (!$hh[0]) public_problem ('Incorrect banner image format. Please try again.'); $cas = time(); $datum = Date('Y-m-d'); dq("insert into $s[tblname] values('$in[username]','$in[password]','$in','$in[siteurl]','$in[urlbanner]','0','0','0','$datum','$cas','0','0',NULL)",1); include('./referral.php'); $in[number] = mysql_insert_id(); $in[memberfile] = "$s[phpdirectory]/member.php"; $in[to] = $in; mail_from_template('email_join.txt',$in); $in[adminfile] = "$s[phpdirectory]/admin/"; $in[memberemail] = $in; $in[to] = $s; mail_from_template('email_admin.txt',$in); $s[workfile]="$s[phpdirectory]/work.php?ID=$in[username]"; $in = parse_part('html.txt',$s); $a[memberfile]="$s[phpdirectory]/member.php"; $in[banner] = '<img border=0 width="'.$s[width].'" height="'.$s[height].'" src="'.$in[urlbanner].'">'; page_from_template('join_success.html',$in); ######################################################################### ?> And than, would be handy if you could give me a script piece which shows users their referral link =$ I mostly appreciate it Quote Link to comment https://forums.phpfreaks.com/topic/238766-problems-with-a-simple-referral-system/ Share on other sites More sharing options...
revraz Posted June 8, 2011 Share Posted June 8, 2011 What is dq before your querries? Quote Link to comment https://forums.phpfreaks.com/topic/238766-problems-with-a-simple-referral-system/#findComment-1226920 Share on other sites More sharing options...
Sigurd Posted June 8, 2011 Author Share Posted June 8, 2011 function dq($query,$check) { global $s; $q = mysql_query($query); if (($check) AND (!$q)) public_problem(mysql_error()); return $q; } Quote Link to comment https://forums.phpfreaks.com/topic/238766-problems-with-a-simple-referral-system/#findComment-1227062 Share on other sites More sharing options...
Sigurd Posted June 8, 2011 Author Share Posted June 8, 2011 I was already able to manage this one with include and redirect (: Quote Link to comment https://forums.phpfreaks.com/topic/238766-problems-with-a-simple-referral-system/#findComment-1227093 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.