我寫了現在非常簡單的貨幣兌換器固定值convertions。我試圖讓它在包含用於計算的PHP腳本的單個文件中工作,並且通過後發送表單發送數據。我的代碼在現在看起來是這樣的:貨幣轉換器在HTML + PHP
<?php
$eurToUsd=1.11;
$usdToEur = 0.94;
$eurToPln = 4.39;
$plnToEur = 0.28;
$usdToPln = 3.87;
$plnToUsd = 0.23;
if (isset($_POST['conversionType'])) {
$eurToUsdVal=$_POST['EURtoUSD'];
$usdToEurVal=$_POST['USDtoEUR'];
$eurToPlnVal=$_POST['EURtoPLN'];
$plnToEurVal=$_POST['PLNtoEUR'];
$usdToPLNVal=$_POST['USDtoPLN'];
$plnToUsdVal=$_POST['PLNtoUSD'];
if ($_POST['EURtoUSD']) {
echo $eurToUsdVal*$eurToUsd;
} elseif ($_POST['USDtoEUR']) {
echo $usdToEurVal*$usdToEur;
} elseif ($_POST['EURtoPLN']) {
echo $eurToPlnVal*$eurToPln;
} elseif ($_POST['PLNtoEUR']) {
echo $plnToEurVal*$plnToEur;
} elseif ($_POST['USDtoPLN']) {
echo $usdToPlnVal*$usdToPln;
} elseif ($_POST['PLNtousUSD']) {
echo $plnToUsdVal*$plnToUsd;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form action="#" method="POST">
<label>
Amount:
<input type="number" min="0.00" step="0.01" name="cashAmount">
</label>
<label>
Conversion:
<input type="radio" name="conversionType" value="EURtoUSD" checked> EUR → USD <br>
<input type="radio" name="conversionType" value="USDtoEUR" > USD → EUR <br>
<input type="radio" name="conversionType" value="EURtoPLN" > EUR → PLN <br>
<input type="radio" name="conversionType" value="PLNtoEUR" > PLN → USD <br>
<input type="radio" name="conversionType" value="USDtoPLN" > USD → PLN <br>
<input type="radio" name="conversionType" value="PLNtoUSD" > PLN → USD <br>
</label>
<input type="submit">
</form>
</body>
</html>
當我試圖用這個轉換器我得到錯誤告訴「未定義指數:EURtoUSD」與同爲其他轉換。準確地說,我得到了這個PHP文件中的所有轉換的錯誤列表。我在這裏想念什麼?
[PHP的可能重複:「通知:未定義變量」和「通知:未定義指數「](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) –