Reputation: 21
I am very new to the whole PHP scene since I just started with this at school, Mostly it has gone pretty good, I am learning a lot. I did however encounter some problems.
I need to make a calculater for KWU (electricity). There must be a choice for paying rate. So far I came up with this:
<?php
if (!empty($_POST['submit'])) {
$KWU = $_POST['KWU'];
if ('tarief1') {
$bedrag = 0.50 * $KWU + 200;
} else {
$bedrag = 0.75 * $KWU + 100;
}
$totaal = $bedrag * 1.19;
echo "KWU = $KWU </br>";
echo "Bedrag = $bedrag </br>";
echo "Bedrag incl. btw = $totaal";
echo "<br>";
echo "<a href=\"energienota.php\">Nog een berekening</a>";
} else {
?>
<html>
<head>
<title>winkelprijs</title>
</head>
<body>
<h2>winkelprijs</h2>
<form method='post' action=''>
KWU <input name='KWU'></br>
Tarief:</br>
<select name="btwtarief">
<option value="tarief1" name="tarief1" id="tarief1">Tarief 1</option>
<option value="tarief2" name="tarief2" id="tarief1">Tarief 2</option>
</select>
<br>
<input name='submit' type='submit' value='bereken'>
<input name='reset' type='reset' value='wissen'>
</form>
</body>
</html>
<?php
}
?>
Now what I don't know is how to get the $tarief1 and $tarief2 choice working. Something with POST I suppose. I hope someone can help me, also sorry for my bad English
Upvotes: 0
Views: 1811
Reputation: 7597
Just change this line:
if('tarief1')
to
if ($_POST['btwtarief'] == 'tarief1')
Btw: also you dont need name
attribute for your option
elements. They have name
of select
element:
<select name="btwtarief">
<option value="tarief1">Tarief 1</option>
<option value="tarief2">Tarief 2</option>
</select>
id
attribute you may need, but I dont think so you will...
Upvotes: 1