<?php
    require_once('session.php');
    $full_name = $_POST['full_name'];
    $no_hp = $_POST['no_hp'];
    $usere = strtolower($_POST['user']);
    $user = str_replace(' ','',$usere);
    $email = $_POST['email'];
    $no_hp = $_POST['no_hp'];
    $pass = password_hash($_POST['pass'],PASSWORD_DEFAULT);
    $pinTrx = md5('123456');
    $level = $_POST['level'];
    $join_date = date('Y-m-d H:i:s');
    
    $cekusere = mysqli_query($conn,"SELECT * FROM `tb_user` ORDER BY cuid DESC LIMIT 1") or die (mysqli_error());
    $cus = mysqli_fetch_array($cekusere);
    $cuid = $cus['cuid'] + 1;
    $useridd = '1'.date('dmy').$cuid;

    $cekemail = mysqli_query($conn,"SELECT * FROM `tb_user` WHERE user = '$user' OR email = '$email'") or die (mysqli_error());
    $q = mysqli_num_rows($cekemail);
    if($q > 0){
        header('location:../user/?notif=2');
    }
    else {
        $query = mysqli_query($conn,"INSERT INTO `tb_user` (`userid`, `extplayer`, `user`, `pass`, `token_id`, `image`, `full_name`, `email`, `no_hp`, `level`, `pinTrx`, `reff`, `uplineID`, `join_date`, `last_login`, `status`) VALUES ('$useridd', '', '$user', '$pass', '0', 'avatar5.png', '$full_name', '$email', '$no_hp', '$level', '', 0, 1, '$join_date', '$join_date', 1)") or die(mysqli_error());
        $last_id = mysqli_insert_id($conn);
        $query2 = mysqli_query($conn,"INSERT INTO `tb_balance` (`userID`, `active`, `pending`, `transfer`, `payout`, `created_date`) VALUES ('$last_id', 0, 0, 0, 0, '$join_date')") or die(mysqli_error());
        header('location:../user/?notif=1');
        exit();
    }
?>