Dollar buy sell php script free download

Dollar buy sell php script free download

Dollar buy sell php script free download .Dollar buy sell WordPress Theme

Here’s a simple PHP script for a Dollar Buy/Sell system. It allows users to input an amount in dollars and get the equivalent in another currency (e.g., PHP or any other). It includes basic conversion logic.


Features:

✔ī¸ Live exchange rate fetching (optional)
✔ī¸ Manual exchange rate input (if no API is used)
✔ī¸ Simple UI with form submission


PHP Script (index.php)

<?php
// Function to fetch live exchange rate (optional)
function getExchangeRate($from_currency, $to_currency) {
    $apiKey = 'YOUR_API_KEY_HERE'; // Replace with a real API key
    $url = "https://api.exchangerate-api.com/v4/latest/$from_currency";
    
    $response = file_get_contents($url);
    if ($response) {
        $data = json_decode($response, true);
        return $data['rates'][$to_currency] ?? false;
    }
    return false;
}

$exchangeRate = 55; // Default exchange rate (e.g., USD to PHP)

if (isset($_POST['convert'])) {
    $amount = floatval($_POST['amount']);
    $type = $_POST['type']; // 'buy' or 'sell'

    // Optionally fetch live exchange rate
    $liveRate = getExchangeRate('USD', 'PHP');
    if ($liveRate) {
        $exchangeRate = $liveRate;
    }

    if ($type === 'buy') {
        $total = $amount * $exchangeRate;
    } else {
        $total = $amount * ($exchangeRate - 0.5); // Slightly lower for selling
    }

    $message = "Converted Amount: " . number_format($total, 2) . " PHP";
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dollar Buy/Sell</title>
</head>
<body>
    <h2>Dollar Exchange System</h2>
    <form method="POST">
        <label>Amount (USD):</label>
        <input type="number" step="0.01" name="amount" required>
        <label>Type:</label>
        <select name="type">
            <option value="buy">Buy</option>
            <option value="sell">Sell</option>
        </select>
        <button type="submit" name="convert">Convert</button>
    </form>

    <?php if (isset($message)) : ?>
        <h3><?php echo $message; ?></h3>
    <?php endif; ?>
</body>
</html>

🔧 How It Works:

  1. The user enters an amount in USD.
  2. Selects Buy (USD to PHP) or Sell (PHP to USD).
  3. The script calculates the total based on a fixed or live exchange rate.
  4. Displays the converted amount.

🚀 Next Steps (Optional Enhancements)

  • Use a database to store exchange rates.
  • Allow admin to set custom rates.
  • Implement an authentication system.

Would you like me to integrate this with a database or add more features? 😊

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *