hello, i want to add a simple user referral system to this free script, hxxp://www.php-login-script.com/ i have added a new field as 'refcount' in the DB with DEFAULT VALUE '0' now all i want is whenever a new user signups with hxxp://mydomain.com/register.php?&id=1234 and complete the signup by verifying his email address then the count field corresponding to the user with id=1234 gets an increment by 1 please help!!!!
After verifying email address: $con = mysql_connect("localhost","qwerty","qwerty"); mysql_select_db("yourDB", $con); $numOfRef=0; $result = mysql_query("SELECT numOfRef FROM users WHERE id=1234"); while($row = mysql_fetch_array($result)) { $numOfRef = $row['numOfRef']; } $numOfRef+=$numOfRef; mysql_query("UPDATE users SET numOfRef = $numOfRef WHERE id = 1234"); mysql_close($con); PHP:
thanks mate but i am facing another problem, since the referral url is like, hxxp://mysite.com/register.php?follow=1234 so i first tried grabbing the "follow" via, $referid = $_REQUEST['follow']; but when i passing this $referid then its giving me blank (attached the screenshot below) here is a portion of register.php file <?php /*************** PHP LOGIN SCRIPT V 2.0********************* ***************** Auto Approve Version********************** (c) Balakrishnan 2009. All Rights Reserved Usage: This script can be used FREE of charge for any commercial or personal projects. Limitations: - This script cannot be sold. - This script may not be provided for download except on its original site. For further usage, please contact me. ***********************************************************/ include 'dbc.php'; if($_POST['doRegister'] == 'Register') { require_once('recaptchalib.php'); $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { die ("<h3>Image Verification failed!. Go back and try again.</h3>" . "(reCAPTCHA said: " . $resp->error . ")"); } $user_ip = $_SERVER['REMOTE_ADDR']; [B]$referid = $_REQUEST['follow'];[/B] $md5pass = md5($_POST['pwd']); $host = $_SERVER['HTTP_HOST']; $host_upper = strtoupper($host); $path = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); $activ_code = rand(1000,9999); $usr_email = mysql_real_escape_string($_POST['usr_email']); $user_name = mysql_real_escape_string($_POST['user_name']); $rs_duplicate = mysql_query("select count(*) as total from users where user_email='$usr_email' OR user_name='$user_name'") or die(mysql_error()); list($total) = mysql_fetch_row($rs_duplicate); if ($total > 0) { $err = urlencode("ERROR: The username/email already exists. Please try again with different username and email."); header("Location: register.php?msg=$err"); exit(); } $sql_insert = "INSERT into `users` (`full_name`,`user_email`,`pwd`,`address`,`tel`,`fax`,`website`,`date`,`users_ip`,`activation_code`,`country`,`user_name` ) VALUES ('$_POST[full_name]','$usr_email','$md5pass','$_POST[address]','$_POST[tel]','$_POST[fax]','$_POST[web]' ,now(),'$user_ip','$activ_code','$_POST[country]','$user_name' )"; mysql_query($sql_insert,$link) or die("Insertion Failed:" . mysql_error()); $user_id = mysql_insert_id($link); $md5_id = md5($user_id); mysql_query("update users set md5_id='$md5_id' where id='$user_id'"); // echo "<h3>Thank You</h3> We received your submission."; $message = "Thank you for registering with us. Here are your login details...\n User ID: $user_name Email: $usr_email \n Passwd: $_POST[pwd] \n Activation code: $activ_code \n echo $referid; *****ACTIVATION LINK*****\n http://$host$path/activate.php?user=$md5_id&activ_code=$activ_code[B]&follow=$referid[/B] [I][COLOR="Green"]//i have added &follow=$referid in the activation link so that when user verify the email then that ID get an increment for referring this user[/COLOR][/I] Thank You Administrator $host_upper ______________________________________________________ THIS IS AN AUTOMATED RESPONSE. ***DO NOT RESPOND TO THIS EMAIL**** "; mail($usr_email, "Login Details", $message, "From: \"Member Registration\" <auto-reply@$host>\r\n" . "X-Mailer: PHP/" . phpversion()); header("Location: thankyou.php"); exit(); } ?> <html> <head> <title>PHP Login.................. . . . . . . . . . . . . . Code (markup): Activation Email Preview:
Nope..... still giving blank :s hxxp://mysite.com/test/activate.php?user=fc490ca45c00b1249bbe3554a4fdf6fb&activ_code=2209&follow= should be like, hxxp://mysite.com/test/activate.php?user=fc490ca45c00b1249bbe3554a4fdf6fb&activ_code=2209&follow=1234
so the form you are using is from the login script right? how is follow added to it? are you setting the action for the script as register.php?follow=<?php echo $follow ; ?> or something similiar? or are you adding the follow parameter as a hidden field ?
@shallowink yes i am using the login script! activate.php?follow=<?php echo $follow ; ?> this is what i am trying to do here :S but it keep giving me blank (as u can see in the picture)
I'm asking about the form before the registering part. Ok I just checked the script. Scroll down to the actual form to register , this line: I would add a hidden form input for the follow. something like <input type="hidden" name="follow" value="<?php echo $follow; ?>" /> And you need to get the $follow from the link to pass it back to itself for processing. clear? Since register.php has effective 2 possible pages it displays. The first is the form itself and the results. You are focusing on the second half (processing the form).
$referid = $_REQUEST['follow']; PHP: activate.php?follow=<?php echo $follow ; ?> // why $follow? mby $referid? PHP:
The entire script isn't showing. the first time the script is called he said it was using the format register.php?&id=1234 so it should be looking for $_GET['id'] not follow. That value needs to be placed in the Form to register. then its submitted. when he sends the activation email, it uses $referid. Also, using the hidden field it will be in $_POST (or $_REQUEST) not GET. clear as mud but oh well.
thanks everyone its now working fine! thanks shallowink your hidden hidden field method does the trick! thanks alot mate!!!