-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurrencyExchange.php
48 lines (40 loc) · 1.4 KB
/
currencyExchange.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Currency Converter</title>
</head>
<body>
<h2>Currency Converter</h2>
<?php
// Function to convert USD to INR
function convertUSDToINR($usdAmount)
{
// Fixed conversion rate (for example purposes)
$conversionRate = 75.0;
return $usdAmount * $conversionRate;
}
// Check if the form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get the USD amount from the form
$usdAmount = $_POST["usd_amount"];
// Validate the input (for demonstration purposes)
if (!empty($usdAmount) && is_numeric($usdAmount)) {
// Convert USD to INR
$inrAmount = convertUSDToINR($usdAmount);
// Display the result
echo "<p>$usdAmount USD is equal to $inrAmount INR</p>";
} else {
echo "<p>Please enter a valid USD amount.</p>";
}
}
?>
<!-- Currency conversion form -->
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<label for="usd_amount">Enter USD amount:</label>
<input type="text" name="usd_amount" id="usd_amount" required>
<input type="submit" value="Convert">
</form>
</body>
</html>