0

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

2
Contributors
7
Replies
8
Views
5 Years
Discussion Span
Last Post by kaosjon
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

0

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

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.

Edited by diafol: n/a

0

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

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.