Emm...als letstes habe ich das kopiert:
[Only registered and activated users can see links. Click Here To Register...]
;D
[Only registered and activated users can see links. Click Here To Register...]
;D
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Adieren und Subtrahieren</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
</head>
<body>
<br><h2>Bitte wählen Sie den Operator:</h2><br><br>
<form action="<? $_SERVER['PHP_SELF'] ?>" method="post">
<table>
<tr>
<th><p>Auswahl</p></th>
<th><p>Operator</p></th>
</tr>
<td><p><br>Addieren</p></td>
<td><br><input type="radio" name="operator" value="1"<? if($_POST['operator'] == 1){ ?> checked<? } ?>></td>
<tr>
<td><p>Subtrahieren</p></td>
<td><input type="radio" name="operator" value="2"<? if($_POST['operator'] == 2){ ?> checked<? } ?>></td>
</tr>
<tr>
<td><input type="submit" value="Auswahl"></td><td></td>
</tr>
</table>
</form>
<br>
<?
/* Check ob Operator gesetzt, dann erste Rechentabelle */
if (isset($_POST['operator']) && $_POST['operator'] == 1 ) {
?>
<form action="<? $_SERVER['PHP_SELF'] ?>" method="post">
<table>
<tr>
<td>Erste Zahl: </td>
<td><input type="text" name="zahl_1" value="<? $_POST['zahl_1'] ?>"></td>
</tr>
<tr>
<td>Zweite Zahl: </td>
<td><input type="text" name="zahl_2" value="<? $_POST['zahl_2'] ?>"></td>
</tr>
<tr>
<td><input type="submit" value="Addieren"></td><td></td>
</tr>
</table>
</form>
<?
/* Check ob alle Variablen gesetzt, numerisch und positiv */
if (isset($_POST['zahl_1']) && isset($_POST['zahl_2']) && (int)$_POST['zahl_1'] > 0 && (int)$_POST['zahl_2'] > 0) {
/* Berechnung der Addition */
$zahl_1 = $_POST['zahl_1'];
$zahl_2 = $_POST['zahl_2'];
$ergebnis_1 = $zahl_1 + $zahl_2;
echo "<br><p>Das Ergebnis ist " .$ergebnis_1. ".</p>";
} else {
echo "<br><p>Die Variablen müssen numerisch und positiv sein!</p>";
}
/* Check ob Operator gesetzt, dann zweite Rechentabelle */
} elseif (isset($_POST['operator']) && $_POST['operator'] == 2 ) {
?>
<form action="<? $_SERVER['PHP_SELF'] ?>" method="post">
<table>
<tr>
<td>Erste Zahl: </td>
<td><input type="text" name="zahl_a" value="<? $_POST['zahl_a'] ?>"></td>
</tr>
<tr>
<td>Zweite Zahl: </td>
<td><input type="text" name="zahl_b" value="<? $_POST['zahl_b'] ?>"></td>
</tr>
<tr>
<td><input type="submit" value="Subtrahieren"></td><td></td>
</tr>
</table>
</form>
<?
/* Check ob Variablen gesetzt, positiv und numerisch */
if (isset($_POST['zahl_a']) && isset($_POST['zahl_b']) && (int)$_POST['zahl_1'] > 0 && (int)$_POST['zahl_2'] > 0) {
/* eigentliche Subtraktion: */
$zahl_a = $_POST['zahl_a'];
$zahl_b = $_POST['zahl_b'];
$ergebnis_2 = $zahl_a - $zahl_b;
echo "<br><p>Das Ergebnis ist " .$ergebnis_2. ".</p>";
} else {
echo "<br><p>Die Variablen müssen numerisch und positiv sein!</p>";
}
} else {
echo "<br><p>Bitte wählen Sie einen Operator!</p>";
}
?>
</body>
</html>
|
|
|
|