I'm working on a referral program script. I've got the below table:
id primary key
name varchar
email varchar
ref varchar
bid varchar
reward boolean
Basically once a three friends join by using the same ref, the person with the id equal to the ref will get a reward.
I need to check everytime that someone subscribe if three same ref are in the table and then set the reward to true and send an email to the person with the id equal to the ref.
I hope that is clear.
I'm struggling to get it done.
Below the whole script so far:
$Bname = mysql_real_escape_string($_POST['Bname']);
$Bemail = mysql_real_escape_string($_POST['Bemail']);
$Bref = mysql_real_escape_string($_POST['Bref']);
$Bid = mysql_real_escape_string($_POST['Bid']);
mysql_connect("******", "******", "*******") or die ('Error: '.mysql_error());
mysql_select_db("********");
$checkEmail = "SELECT email FROM betalist WHERE email ='".$Bemail."'";
$result = mysql_query($checkEmail);
if (mysql_num_rows($result) > 0) {
echo $Bemail." is already in our list";
exit;
}
if (mysql_num_rows($result) == 0) {
$query="INSERT INTO betalist (ID, name, email,ref,bid)VALUES ('NULL','".$Bname."','".$Bemail."','".$Bref."','".$Bid."')";
mysql_query ($query) or die ('Error updating database');
So far I've tried to work it out using the mysql_num_rows:
$refCount = "SELECT id, email FROM betalist WHERE ref='".$Bref."'";
$result = mysql_query($refCount);
if (mysql_num_rows($result)==3)
{
echo $countarray;
}
Can you help me?