<?php
session_start();
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
 
$conn= new mysqli('das115.truehost.cloud','honyehtx_honyehtx','B7PcCzi46xP(*8','honyehtx_mavy')or die("Could not connect to mysql".mysqli_error($conn));
 

// Redirect to login if user is not logged in
if (!isset($_SESSION['email'])) {
    header("Location: ../auth/login.php");
    exit();
}

// Get user email from session
$userEmail = $_SESSION['email'];

// Fetch user info from database
$query = "SELECT * FROM user WHERE email = '$userEmail' LIMIT 1";
$result = mysqli_query($conn, $query);

if (mysqli_num_rows($result) === 1) {
    $user = mysqli_fetch_assoc($result);
} else {
    echo "User not found.";
    exit();
}
?>


 <?php
if (isset($_POST['linkone'])) {

    // Sanitize inputs
    $name = mysqli_real_escape_string($conn, $_POST['name']);
    $fee = mysqli_real_escape_string($conn, $_POST['fee']);
    $profit = mysqli_real_escape_string($conn, $_POST['profit']);
    $emailorphon = mysqli_real_escape_string($conn, $_POST['emailorphon']);
    
    
    
    ///// 🔍 Get user balance from user table
    $checkBalance = "SELECT balance FROM user";
    $result = mysqli_query($conn, $checkBalance);
    if (mysqli_num_rows($result) > 0) {
        $row = mysqli_fetch_assoc($result);
        $balance = $row['balance'];
        
    if ($fee > $balance) {
            // ❌ Fee is greater than balance
            echo "<script>alert('Insufficient balance..'); 
            window.location.href='copy_trader.php';</script>";
            exit(); // stop further execution
        }
    
    
    }
    
    
    

    // Insert into trade table
    $insert = "INSERT INTO trade (name, fee, profit, emailaddres)
               VALUES ('$name', '$fee', '$profit', '$emailorphon')";
    
    $data = mysqli_query($conn, $insert);

    // ✅ Check if insert was successful
    if ($data) {
        // ✅ Show success message and redirect  echo "
        echo "<script>alert('Request submitted successfully. \\n\\nNote: Capital Investment will be deducted from your Balance. \\n\\nYou can contact Admin on our Live Support Engine'); 
        window.location.href='';</script>";
    } else {
        echo "<script>alert('Submission failed. Please try again.'); 
        window.location.href='copy_trader.php';</script>";
    }
}
?>





 <?php
if (isset($_POST['linktwo'])) {

    // Sanitize inputs
    $name = mysqli_real_escape_string($conn, $_POST['name']);
    $fee = mysqli_real_escape_string($conn, $_POST['fee']);
    $profit = mysqli_real_escape_string($conn, $_POST['profit']);
    $emailorphon = mysqli_real_escape_string($conn, $_POST['emailorphon']);
    
    ///// 🔍 Get user balance from user table
    $checkBalance = "SELECT balance FROM user";
    $result = mysqli_query($conn, $checkBalance);
    if (mysqli_num_rows($result) > 0) {
        $row = mysqli_fetch_assoc($result);
        $balance = $row['balance'];
        
    if ($fee > $balance) {
            // ❌ Fee is greater than balance
            echo "<script>alert('Insufficient balance..'); 
            window.location.href='copy_trader.php';</script>";
            exit(); // stop further execution
        }
    
    
    }
    
    
    

    // Insert into trade table
    $insert = "INSERT INTO trade (name, fee, profit, emailaddres)
               VALUES ('$name', '$fee', '$profit', '$emailorphon')";
    
    $data = mysqli_query($conn, $insert);

    // ✅ Check if insert was successful
    if ($data) {
        // ✅ Show success message and redirect  echo "
        echo "<script>alert('Request submitted successfully. \\n\\nNote: Capital Investment will be deducted from your Balance. \\n\\nYou can contact Admin on our Live Support Engine'); 
        window.location.href='';</script>";
    } else {
        echo "<script>alert('Submission failed. Please try again.'); 
        window.location.href='copy_trader.php';</script>";
    }
}
?>



 <?php
if (isset($_POST['linkthree'])) {

    // Sanitize inputs
    $name = mysqli_real_escape_string($conn, $_POST['name']);
    $fee = mysqli_real_escape_string($conn, $_POST['fee']);
    $profit = mysqli_real_escape_string($conn, $_POST['profit']);
    $emailorphon = mysqli_real_escape_string($conn, $_POST['emailorphon']);
    
    ///// 🔍 Get user balance from user table
    $checkBalance = "SELECT balance FROM user";
    $result = mysqli_query($conn, $checkBalance);
    if (mysqli_num_rows($result) > 0) {
        $row = mysqli_fetch_assoc($result);
        $balance = $row['balance'];
        
    if ($fee > $balance) {
            // ❌ Fee is greater than balance
            echo "<script>alert('Insufficient balance..'); 
            window.location.href='copy_trader.php';</script>";
            exit(); // stop further execution
        }
    
    
    }
    
    
    

    // Insert into trade table
    $insert = "INSERT INTO trade (name, fee, profit, emailaddres)
               VALUES ('$name', '$fee', '$profit', '$emailorphon')";
    
    $data = mysqli_query($conn, $insert);

    // ✅ Check if insert was successful
    if ($data) {
        // ✅ Show success message and redirect  echo "
        echo "<script>alert('Request submitted successfully. \\n\\nNote: Capital Investment will be deducted from your Balance. \\n\\nYou can contact Admin on our Live Support Engine'); 
        window.location.href='';</script>";
    } else {
        echo "<script>alert('Submission failed. Please try again.'); 
        window.location.href='copy_trader.php';</script>";
    }
}
?>








<?php
if (isset($_POST['linkfour'])) {

    // Sanitize inputs
    $name = mysqli_real_escape_string($conn, $_POST['name']);
    $fee = mysqli_real_escape_string($conn, $_POST['fee']);
    $profit = mysqli_real_escape_string($conn, $_POST['profit']);
    $emailorphon = mysqli_real_escape_string($conn, $_POST['emailorphon']);
    
    ///// 🔍 Get user balance from user table
    $checkBalance = "SELECT balance FROM user";
    $result = mysqli_query($conn, $checkBalance);
    if (mysqli_num_rows($result) > 0) {
        $row = mysqli_fetch_assoc($result);
        $balance = $row['balance'];
        
    if ($fee > $balance) {
            // ❌ Fee is greater than balance
            echo "<script>alert('Insufficient balance..'); 
            window.location.href='copy_trader.php';</script>";
            exit(); // stop further execution
        }
    
    
    }
    
    
    

    // Insert into trade table
    $insert = "INSERT INTO trade (name, fee, profit, emailaddres)
               VALUES ('$name', '$fee', '$profit', '$emailorphon')";
    
    $data = mysqli_query($conn, $insert);

    // ✅ Check if insert was successful
    if ($data) {
        // ✅ Show success message and redirect  echo "
        echo "<script>alert('Request submitted successfully. \\n\\nNote: Capital Investment will be deducted from your Balance. \\n\\nYou can contact Admin on our Live Support Engine'); 
        window.location.href='';</script>";
    } else {
        echo "<script>alert('Submission failed. Please try again.'); 
        window.location.href='copy_trader.php';</script>";
    }
}
?>




<?php
if (isset($_POST['linkfive'])) {

    // Sanitize inputs
    $name = mysqli_real_escape_string($conn, $_POST['name']);
    $fee = mysqli_real_escape_string($conn, $_POST['fee']);
    $profit = mysqli_real_escape_string($conn, $_POST['profit']);
    $emailorphon = mysqli_real_escape_string($conn, $_POST['emailorphon']);
    
    ///// 🔍 Get user balance from user table
    $checkBalance = "SELECT balance FROM user";
    $result = mysqli_query($conn, $checkBalance);
    if (mysqli_num_rows($result) > 0) {
        $row = mysqli_fetch_assoc($result);
        $balance = $row['balance'];
        
    if ($fee > $balance) {
            // ❌ Fee is greater than balance
            echo "<script>alert('Insufficient balance..'); 
            window.location.href='copy_trader.php';</script>";
            exit(); // stop further execution
        }
    
    
    }
    
    
    

    // Insert into trade table
    $insert = "INSERT INTO trade (name, fee, profit, emailaddres)
               VALUES ('$name', '$fee', '$profit', '$emailorphon')";
    
    $data = mysqli_query($conn, $insert);

    // ✅ Check if insert was successful
    if ($data) {
        // ✅ Show success message and redirect  echo "
        echo "<script>alert('Request submitted successfully. \\n\\nNote: Capital Investment will be deducted from your Balance. \\n\\nYou can contact Admin on our Live Support Engine'); 
        window.location.href='';</script>";
    } else {
        echo "<script>alert('Submission failed. Please try again.'); 
        window.location.href='copy_trader.php';</script>";
    }
}
?>














   
