I Want to Create Refer System With Mysql But I Want User Enter Refer After Registration
<?php
include 'conn.php';
include 'add_user.php';
// Refer system
$sql2="SELECT * FROM invest_user WHERE `Refer_code`='$refer_by'";
$result=mysqli_query($conn,$sql2);
$row=mysqli_fetch_array($result);
$newbalance=$row['Balance']+$amount;
$sql3="UPDATE invest_user SET `Balance`='$newbalance' WHERE `refer_code`='$refer_by'";
$result2=mysqli_query($conn,$sql3);
// Refer System End x-x-x
?>
this is my refer system code but it work with registration process but don’t work alone means i want to make refer system after registration
this is my Registration Code
<?php
include 'conn.php';
$name=$_GET["name"];
$phone=$_GET["phone"];
$password=$_GET["password"];
$balance=$_GET["balance"];
$total_referrals=$_GET["total_referrals"];
$refer_code=$_GET["refer_code"];
$refer_by=$_GET["refer_by"];
$total_withdraw=$_GET["total_withdraw"];
$refer_earning=$_GET["refer_earning"];
$ads_view=$_GET["ads_view"];
$tx_id=$_GET["tx_id"];
$package=$_GET["package"];
$expiry_date=$_GET["expiry_date"];
$amount=$_GET["refer_amount"];
// Checking whether phone is Already Exist or Not in MySQL Table.
$CheckSQL = "SELECT * FROM invest_user WHERE phone='$phone'";
// Executing phone Check MySQL Query.
$check = mysqli_fetch_array(mysqli_query($conn,$CheckSQL));
// Refer system
$sql2="SELECT * FROM invest_user WHERE `Refer_code`='$refer_by'";
$result=mysqli_query($conn,$sql2);
$row=mysqli_fetch_array($result);
$newbalance=$row['Balance']+$amount;
$sql3="UPDATE invest_user SET `Balance`='$newbalance' WHERE `refer_code`='$refer_by'";
$result2=mysqli_query($conn,$sql3);
// Refer System End x-x-x
if(isset($check)){
echo 'Phone Number Already Exist!';
}
else{
// Creating SQL query and insert the record into MySQL database table.
$sql="INSERT INTO invest_user (Phone,Name,Password,Balance,Total_referrals,Refer_code,Refer_by,Total_withdraw,Refer_earning,Ads_view,Tx_id,Package,Expiry_date) VALUES ('$phone','$name','$password','$balance','$total_referrals','$refer_code','$refer_by','$total_withdraw','$refer_earning','$ads_view','$tx_id','$package','$expiry_date')";
if(mysqli_query($conn,$sql)){
echo "User Data Created";
}else
{
echo "Failed to Create User";
}
}
?>
This is my Database Structure : Please Help ME