954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Not updating number of referals

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)
	 {
		
		mysql_query("UPDATE referrals SET no_of_referrals = no_of_referrals + '1' WHERE username = '$referal'");
	 }


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

kaosjon
Light Poster
37 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 
"UPDATE referrals SET no_of_referrals = no_of_referrals +1 WHERE username = '$referal'"


no need for quotes around 1.
echo out the sql to see if its what you expect

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

Hi, i removed the quotes around the 1 and still does not add the referal. I then tried to echo out the query but it just goes to a white screen with no output. I removed the include at the end as it goes to a seperate page, so you won't see the echo, but when it reloads onto registration.php its just a white screen.

Any ideas?

Thanks

kaosjon
Light Poster
37 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 
if($referal_check > 0)
	 {
 echo "UPDATE referrals SET no_of_referrals = no_of_referrals + 1 WHERE username = '$referal'";
		mysql_query("UPDATE referrals SET no_of_referrals = no_of_referrals + 1 WHERE username = '$referal'");
	 }
echo "SELECT username FROM user_info WHERE username='$referal'";
$sql_referal_check = mysql_query("SELECT username FROM user_info WHERE username='$referal'");
     $referal_check = mysql_num_rows($sql_referal_check);


I didn't understand any of the include stuff you stated as it's not included in the code you supplied, so the above is what I suggest.

If you don't get any output from the UPDATE echo, it's because the $referal_check is not > 0.
If you do get output - copy the output to the screen and paste it into phpmysql and see if it works.

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

Hi, sorry about the include stuff, didnt realise i did not include the code.

I entered the two echo commands but i only get one output

SELECT username FROM user_info WHERE username='admin1'


And when i tried the above code in phpmysql i get the username show up. I am guessing that because the second echo did not show it means that it is not recognizing the referal_check as being greater than 0. I will try and have a play around with the if statement (referal_check > 0) Any advice you can give i would greatly appreciate.

Thanks

kaosjon
Light Poster
37 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

Hi, i have tried everything i can think of but it is still not working, the query works but it is not submitting it in the table.

Any ideas?

Thanks

kaosjon
Light Poster
37 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

once again it seems to be the

if($referal_check > 0)


Try taking it off to see what happens.

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

Brilliant it works now, thanks a lot

kaosjon
Light Poster
37 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: