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 8 of 8
  1. #1
    Regular Coder
    Join Date
    Apr 2006
    Posts
    117
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Add 50 each time someone enters a Username

    Hey guys,

    I've been trying to add a referrer mod to my PHPBB, but have had little luck so I am attempting to make my own.

    I want to make a PHP script that will add 50 to a table field in MySQL every time someone enters a username into a field.

    Here is the HTML I am going to add

    Code:
    <input type="text" value="Referrer" />
    I want that to add 50 to my MySQL table field "user_refer."

    If the user does not exist I want it to ignore that part of the PHP and move on.

    So, lets say Johnny joins the forum and was referred by Josh. Josh has 500 referral points. If Johnny submits the form with Josh's name in the Refer field then Josh should receive 50 more points thus making 550. If he spells it Josh "Jsoh," I want the script to continue so Johnny still becomes a registered member.

    I am still learning about PHP but I think I got an idea with what I need to do...

    Something like

    PHP Code:
    $refer $_POST['refer']

    SELECT user_refer FROM phpbb_users WHERE username "$refer"
    Now, that I have it I need to add 50 to it and then reinsert it.

    But, I do not know how to make the above line a variable or how to copy over the existing MySQL entry of 500 and make it 550.

  • #2
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    UPDATE phpbb_users SET user_refer = user_refer + 50 WHERE username="$refer"

    mind that $refer is escaped or validated.

  • #3
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    why not have referal links for each referer
    www.yoursite.com/phpbb/register.php?in=username
    that way it will save your users adding the username to who refered them
    then just use an if statement to see if in isset()
    if it is run the statement ralph suggested above
    Last edited by rafiki; 03-27-2007 at 08:39 PM.

  • #4
    Regular Coder
    Join Date
    Apr 2006
    Posts
    117
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Ralph, wouldn't a receive errors if $refer doesn't exist in the database? How would I get around that?

    "mind that $refer is escaped or validated."

    That may be answering my question above, but I am not positive what it means.

    I think you are saying that $refer will either work or not, thus allowing the rest of the script to parse without receiving errors. I may be wrong.

    Rafiki, the reason I am doing it this way is because some people may be referred from word of mouth, not just links.

    Although, how would I do what you are saying?

    Like this?

    link = mysite.com/register.php?refer=username

    PHP Code:

    if (isset($refer)) {
    UPDATE phpbb_users SET user_refer user_refer 50 WHERE username="$refer"

    Last edited by Tyrial101; 03-27-2007 at 08:49 PM.

  • #5
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Quote Originally Posted by Tyrial101 View Post
    Because not everyone will be referred through a link. Some people may be referred through word of mouth.
    ok but you could still run the if statement and if in isnt set, ask them where they found yoursite, add some javascript to add anouther field for the appropriate
    response

  • #6
    Regular Coder
    Join Date
    Apr 2006
    Posts
    117
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Well, that is what I think I am going to do now that you mention it.

    If the user did not connect through a referral link, then the <input> tag for Referrer will show up, otherwise it will just be a hidden input with a value of $refer.

    Something like this I think

    PHP Code:
    if (isset($refer)) {
    echo(
    '<input type=\"hidden\" value=\"$refer\" />')
    }

    else {
    echo(
    '<input type=\"text\" value=\"Referrer\" />')


  • #7
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    you got it

  • #8
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Ralph, wouldn't a receive errors if $refer doesn't exist in the database? How would I get around that?
    An update query that doesn't update anything will not throw an error. You can call the function mysql_affected_rows() to find out how many rows the update query updated, and take action from there.


  •  

    Posting Permissions

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