Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Referring Users

  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Location
    Scotland
    Posts
    134
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Referring Users

    Hi Guys,

    I'm trying to think of a way to give users credit for referring other users, in each users account there is a link: http://www.site.com/sign-up.php?r=8 <-- is is the users ID.


    when new users goto: http://www.site.com/sign-up.php?r=8 to signup what would be the best way to give user 8 the credit for signing up another user?

    thanks for any help guys

    Graham

  • #2
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    For each user in the table, have a column with "referrer" and set the referrer to the referrers id when they sign up, so say user 50 signs up, their referrer would be set to 8 in your example
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #3
    Regular Coder seco's Avatar
    Join Date
    Nov 2008
    Location
    Oregon
    Posts
    687
    Thanks
    6
    Thanked 79 Times in 77 Posts
    or have a table referrer with the columns

    ref_id
    user_id
    reffered_times


    have the link goto a different page like

    domain.com/ref.php?r=8

    run the query to that table to insert/update

    example

    Code:
    INSERT INTO referrer (user_id, referred_times)
    VALUES(userid= '8', referred_times = +1)
    ON DUPLICATE KEY UPDATE referred_times = +1

    something along those lines, im not much of a mysql guy.

    and header it to the sign up page. this way you have a table to work with for referrers.
    Last edited by seco; 01-23-2010 at 11:43 PM.

  • #4
    Regular Coder
    Join Date
    Jul 2007
    Location
    Scotland
    Posts
    134
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Hi Guys,

    Thanks for the reply, my sign-up.php page code:

    PHP Code:
    <?php
    include("inc/inc-dbconnection.php");
    include(
    "inc/inc-online.php");
    include(
    "inc/inc-functions.php");
    include(
    "inc/inc-header.php");
    include(
    "inc/inc-arrays.php");
    ?>
    <div class="fcp-main-content-area">    
     <div class="fcp-breadcrumb">
      <ul>
         <li><a href="index.php">Home</a></li> >>
         <li><a href="javascript:history.go(-1)">Previous Page</a></li> >>
         <li>Sign up for an account.</li>
        </ul>
    </div>
    <?php
    if (isset($_POST['submitSignUp']))
    {
       
    // Errors array()
       
    $errors = array();

       
    // POST vars
       
    $fName mysql_real_escape_string($_POST['fname']);
       
    $lName mysql_real_escape_string($_POST['lname']); 
       
    $email mysql_real_escape_string($_POST['email']); 
       
    $pass1 mysql_real_escape_string($_POST['pass1']); 
       
    $pass2 mysql_real_escape_string($_POST['pass2']); 
       
    $cntry mysql_real_escape_string($_POST['cntry']); 
       
       
    // Referred
       
    if ($_POST['r'] != 0)
       {
         
    $r $_POST['r'];
       }
       
       
    // Potential errors 
       // Empty fields
       
    if (empty($fName) || empty($lName) || empty($email) || empty($pass1) || empty($pass2)) { 
            
    $errors[] = "You never filled in all the fields."
       } else {
       
           
    // Does passwords match
           
    if ($pass1 != $pass2)
           {
              
    $errors[] = "Your passwords don't match."
           }
        
           
    // Does user exist? 
           
    $result mysql_query("SELECT * FROM `fso_users` WHERE `user_email`='$email' LIMIT 1"); 
           if (
    mysql_num_rows($result) > 0) {    
              
    $errors[] = "The e-mail address <b>$email</b> has already been registered.";  
           } else {

              
    // Insert into the db
              
    $o mysql_query("INSERT INTO `fso_users` (`user_id`,`user_email`,`user_password`,`user_fname`,`user_lname`,`user_country`,`user_referred_by`,`user_date`) VALUES ('','$email','$pass1','$fName','$lName','$cntry','$r',NOW())");

              if (
    $o)
              {

              
    // How many points does a ref get?
              //$points = refPoints();

              // ONLY award the referrer points if everything went ok!
              
    $updatePoints mysql_query("UPDATE `fso_users` SET `offer_views`=offer_views+$points WHERE `user_id`='$r'");
                
              } 

           }
       }  
       
       
    // display errors if any exist
       
    if (count($errors) > 0
       { 
           print 
    "<div id=\"error\">"
           foreach(
    $errors as $error
           { 
              print 
    "&nbsp;<b>X</b> $error<br />"
           }
           print 
    "</div>";
       } else {
           print 
    "<div id=\"success\"><b>></b>&nbsp;All Done! we  have sent an e-mail to <b>$email</b>, you can now log into your account.</div>";
       }

    }
    ?>
    <?php
     
    // Has the user been referred?
     
    if (isset($_GET['r']))
     {
       
    $hidVal $_GET['r'];
     } else {
       
    $hidVal 0
     }
    ?>
    <div id="div-regForm">
    <div class="form-title">Sign Up</div>
    <div class="form-sub-title">Earn points & get free prizes!</div>
    <form id="regForm" action="sign-up.php" method="post">
    <table>
      <tbody>
      <tr>
        <td><label for="fname">First Name:</label></td>
        <td><div class="input-container"><input name="fname" id="fname" type="text" value="<?php print $_POST['fname']; ?>" /></div></td>
      </tr>
      <tr>
        <td><label for="lname">Last Name:</label></td>
        <td><div class="input-container"><input name="lname" id="lname" type="text" value="<?php print $_POST['lname']; ?>" /></div></td>
      </tr>
      <tr>
        <td><label for="email">Your Email:</label></td>
        <td><div class="input-container"><input name="email" id="email" type="text" value="<?php print $_POST['email']; ?>" /></div></td>
      </tr>
      <tr>
        <td><label for="pass">Password:</label></td>
        <td><div class="input-container"><input name="pass1" id="pass1" type="password" value="<?php print $_POST['pass1']; ?>" /></div></td>
      </tr>
      <tr>
        <td><label for="pass">Confirm Password:</label></td>
        <td><div class="input-container"><input name="pass2" id="pass2" type="password" value="<?php print $_POST['pass2']; ?>" /></div></td>
      </tr>
      <tr>
        <td><label for="cntry">Country:</label></td>
        <td><div class="input-container"><select name="cntry"><?php foreach($countryArray as $country) { print "<option value=\"$country\">$country</option>"; } ?></select></div></td>
      </tr>
      <tr>
      <td>&nbsp;</td>
      <td><input name="r" type="hidden" value="<?php print $hidVal?>" /><input type="submit" class="greenButton" name="submitSignUp" value="Sign Up" /></td>
      </tr> 
      </tbody>
    </table>
    </form>
    </div>  
    <?php
    include("inc/inc-footer.php");
    ?>
    If i gave you the link to sign up under like: http://www.site.com/sign-up.php?r=8 to signup under i can't get the value of "r" is there a way to get it like i have done above?

    thanks guys

    Graham


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •