Hi,
ich hoffe, ihr könnt mir helfen. Es wird immer 0 als Ergebnis bei der Umrechnung ausgegeben. Ich weiß nicht, warum das so ist. Das Script habe ich nach einem Buch (!) gemacht, da ich noch php-Anfänger bin. Lediglich die Variablen Namen sowie den Aufbau habe ich geändert. In dem Buch wurde alles in den php-Teil geschrieben. Deshalb habe ich das Script auch nochmal genauso wie in dem Buch (gleiche Variablennamen etc.) gemacht. Leider stellte ich schon öfters fest, dass das Buch Fehler enthält. Ich habe das Script durchgrast, aber ich finde partout keinen Fehler. Hier ist erstmal das Script.
PHP
<?='<?xml version="1.0" encoding="utf-8"?>';?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">
<head>
<title>{php/currency}.dermazta</title>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
</head>
<body>
<?php
if ($_POST['amount']) // Prüfung, ob Feld ausgefüllt
{
$from = array('dm' => 0.51, 'usd' => 1.21, 'gbp' => 0.66, 'euro' => 1);
$to = array('dm' => 1/$from['dm'], 'usd' => 1/$from['usd'], 'gbp' => 1/$from['gbp'], 'euro' => 1);
$result = $from[$_POST['cfrom']] * $_POST['amount'] * $to[$_POST['cto']];
echo "
".$_POST['amount']." ".$_POST['cfrom']." sind ".$result." ".$_POST['cto'].".</p>";
}
?>
<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
Währung
<select name="cfrom" size="1">
<?php
echo "<option"; if ($_POST['cfrom'] == 'dm') { echo "selected"; } echo ">DM</option>";
echo "<option"; if ($_POST['cfrom'] == 'usd') { echo "selected"; } echo ">USD</option>";
echo "<option"; if ($_POST['cfrom'] == 'gbp') { echo "selected"; } echo ">GBP</option>";
echo "<option"; if ($_POST['cfrom'] == 'euro') { echo "selected"; } echo ">Euro</option>";
?>
</select>
Zielwährung
<select name="cto" size="1">
<?php
echo "<option"; if ($_POST['cto'] == 'dm') { echo "selected"; } echo ">DM</option>";
echo "<option"; if ($_POST['cto'] == 'usd') { echo "selected"; } echo ">USD</option>";
echo "<option"; if ($_POST['cto'] == 'gbp') { echo "selected"; } echo ">GBP</option>";
echo "<option"; if ($_POST['cto'] == 'euro') { echo "selected"; } echo ">Euro</option>";
?>
</select>
Betrag
<input name="amount" size="20" type="text" value="<?=$_POST['amount'];?>" />
<input name="submit" type="submit" value="konvertieren" /></p>
</form>
</body>
</html>
Alles anzeigen
Vielen Dank für eure Hilfe
// edit Kann mir wirklich keiner helfen