<?php

require 'config.php';

$sql = $con->query("SELECT * FROM users WHERE user_id = '$user_id' AND auth = '$auth'") or die("Error2 : ". mysqli_error($con));



$rows = mysqli_fetch_array($sql);
$ref = $rows['referral'];
$com = 0.3*$package_amount;

if($ref !== "")
{

$sqlx = $con->query("SELECT * FROM users WHERE ref_code = '$ref'") or die("Error2 : ". mysqli_error($con));
$rowx = mysqli_fetch_array($sqlx);

$bal = $rowx['balance'];
$user = $rowx['user_id'];

$narration = "Referral Commision";


$new_bal = $bal + $com;


$update2=$con->query("UPDATE users SET balance = '$new_bal' WHERE ref_code = '$ref'") or die ("error: Server error ".mysqli_error($con));


   $insert=$con->query("INSERT INTO ref_trans (user, amount, trans_type, method, prev_bal, new_bal, trans_ref, descr,  date_t) 
     VALUES ('$user', '$com', 'WPayout', 'Commision', '$bal', '$new_bal', '$trans_ref', '$narration',  '$date_t')") or die("Error: ".mysqli_error($con));

}


?>