Jump to content

Not updating number of referals


kaosjon

Recommended Posts

Hi, i am just adding the last component to my registration page, but i am having a little trouble with it. Basically my website includes a referal based system, wherebye when the user signs up they can add a referal that benefits the referal later on. The code i am trying to add is to increase the number of referals a member has by 1. It might sound a bit confusing and trust me its taken a few hours to get my head around it, but my code must find the information of the referal and update their number of referals by 1. The code i have below is what i think should work, but it does not update the number of referals by 1.

 

if($referal_check > 0)
 {

//Select everything from user_info where the username is the same as the referal entered by registering user
	$sql_referal = ("SELECT * FROM user_info WHERE username = $referal");
	$result = mysql_query($sql_result);
	$referal_fetch = mysql_fetch_array($result);

//Select everything from referrals table where the id in the table is the same as the id from user from $sql_referal query		
	$sql_referrals = ("SELECT * FROM referrals WHERE id = $id");
	$result_referal = mysql_query($sql_referrals);
	$referrals_fetch = mysql_fetch_array($result_referal);

//Update referrals table setting the no_of referals to + 1 where the id is the same as the id from $sql_referrals		
	mysql_query("UPDATE referrals SET no_of_referrals = no_of_referrals + '1' WHERE id = $id"); 
 }

 

The referal_check is a query to find whether the referal exists in the system, the code is below

 

$sql_referal_check = mysql_query("SELECT username FROM user_info WHERE username='$referal'");
     $referal_check = mysql_num_rows($sql_referal_check);

 

 

Sorry if this is a bit confusing, please ask if you need some more clarification on the code.

 

Thanks

Link to comment
Share on other sites

You've used the variable $id twice and I cannot see where you set this value.

 

Echo out the variable $id and see what it holds,  I'm guessing it holds nothing and you will need to set it with the ID of the referring user.

Try the above out and tell me how it goes.

 

Regards, PaulRyan.

Link to comment
Share on other sites

Hi, i thought about what you said and i think i found an easier way to do this by adding the username field to the referrals table, that way i don't have to keep searching for the id, i can use the referal variable already stored in the code higher up in the script.

 

Heres the new code but it still does not work

 


 if($referal_check > 0)
 {

	mysql_query("UPDATE referrals SET no_of_referrals = no_of_referrals + '1' WHERE username = '$referal'");
 }

 

I tested the query in the sql query page in phpmyadmin changing the $referal to the referal a user would enter and it worked, but for some reason it is not working when i add the query to my site.

 

Any other ideas, thanks

Link to comment
Share on other sites

It really does sound like a variable is not being set, try echoing out $referal_check AND $referal to see what values they hold, if they are holding the correct values then it may be something else that I have missed, I'll be able to havea proper look at your code abit later today.

 

Regards, PaulRyan.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.