Refer System With Mysql

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

Instead of using plane php, start using franeworks. Laravel is a great php framework

can i do it in kodular?

Mysql run in hosting server. In Kodular u make web requests and u can use/save data using web component.

can you edit my code make it correctly working code please?

Also you can see this guide:

Is this is an earning app or what

no this is investment app


In my case not problem in kodular problem in my code

See the php code provided at the end of the website.

please check my code in top of the post

1 Like

You can compare your code with taifun’s code and see what’s wrong.

User enter before ?

1 Like

If you are making investment app then make some complex script.
Your script and also your entire database is easily hackable with browser only.
Seriously you will be in problem make backend powerful to prevent sql attacks and hacking

1 Like

Create a TRIGGER / Stored Procedure in your Database.

Both are different.

1 Like

This is why i recommend usage of a framework

1 Like

That why i told him to compare the two codes.

I agree.
And I think that @appdeveloper547 have to study a little more about PHP, Framework, Database, Security and everything you will need in your project.

Don’t get me wrong. :+1:

Yes backend is backbone of app and websites.
That’s why i learned many backend language.

i prefer nodejs over php

Ok Thanks TO YOu tooo All :smiling_face_with_three_hearts:

1 Like