berekening klopt niet als eenheid meer dan 1 is
Code (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
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
<form action="processorder.php" method=post>
<table border=0>
<tr bgcolor=#cccccc>
<td width=150>Item</td>
<td width=15>Quantity</td>
</tr>
<tr>
<td>Tires</td>
<td align=center><input type="text" name="tireqty" size=3 maxlength=3></td>
</tr>
<tr>
<td>Oil</td>
<td align=center><input type="text" name="oilqty" size=3 maxlength=3></td>
</tr>
<tr>
<td>Spark plugs</td>
<td align=center><input type="text" name="sparkqty" size=3 maxlength=3></td>
</tr>
<tr>
<td>Address</td>
<td align=center><input type="text" name="address" size=40 maxlength=40></td>
</tr>
<tr>
<td>How did you find Bob's</td>
<td><select name="find">
<option value ="a">I am a regular customer</option>
<option value ="b">tv advertising</option>
<option value ="c">Phone directory</option>
<option value ="d">world of mouth</option>
</select>
</td>
</tr>
<tr>
<td colspan=2 align=center><input type=submit value="Submit Order"></td>
</tr>
</table>
</form>
<table border=0>
<tr bgcolor=#cccccc>
<td width=150>Item</td>
<td width=15>Quantity</td>
</tr>
<tr>
<td>Tires</td>
<td align=center><input type="text" name="tireqty" size=3 maxlength=3></td>
</tr>
<tr>
<td>Oil</td>
<td align=center><input type="text" name="oilqty" size=3 maxlength=3></td>
</tr>
<tr>
<td>Spark plugs</td>
<td align=center><input type="text" name="sparkqty" size=3 maxlength=3></td>
</tr>
<tr>
<td>Address</td>
<td align=center><input type="text" name="address" size=40 maxlength=40></td>
</tr>
<tr>
<td>How did you find Bob's</td>
<td><select name="find">
<option value ="a">I am a regular customer</option>
<option value ="b">tv advertising</option>
<option value ="c">Phone directory</option>
<option value ="d">world of mouth</option>
</select>
</td>
</tr>
<tr>
<td colspan=2 align=center><input type=submit value="Submit Order"></td>
</tr>
</table>
</form>
en de php code
Code (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
//create short variable names
$tireqty = $_POST['tireqty'];
$oilqty = $_POST['oilqty'];
$sparkqty = $_POST['sparkqty'];
$address = $_POST['address'];
$find = $_POST['find'];
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
$date = date('H:i; jS F Y');
?>
<html>
<head>
<title>Bob's Auto parts - Order Results</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Order Results</h2>
<?php
echo "<p>Order processed at ";
echo date("H:i, jS F");
echo "<br>";
echo "<p>Your order is as follows: </p>";
$totalqty = 0;
$totalqty = $tireqty + $oilqty + $sparkqty;
if ($totalqty == 0) {
echo "You did not order anything on the previous page!<br />";
} else {
if ($tireqty > 0) {
echo $tireqty." tires<br />";
}
if ($oilqty > 0) {
echo $oilqty." bottle(s) of oil<br />";
}
if ($sparkqty > 0) {
echo $sparkqty." Spark Plugs<br />";
}
}
$totalamount = 0.00;
define('TIREPRICE', 100);
define('OILPRICE', 10);
define('SPARKPRICE', 4);
$totalamount = $tireqty * TIREPRICE
+ $oilqty * OILPRICE
+ $sparkqty * SPARKPRICE;
$totalamount=number_format($totalamount, 2);
echo "<br>\n";
echo "Items ordered: ".$totalqty."<br />\n";
echo "Subtotal: $".$totalamount."<br />\n";
$taxrate =0.10; //local salestax is 10%
$totalamount = $totalamount + ($totalamount * $taxrate);
$totalamount=number_format($totalamount, 2);
echo "Total including tax: $".$totalamount."<br />\n";
echo "<p>Address to ship to is ".$address."</p>";
if($find == "a")
echo "<p>Regular customer. </p>";
elseif($find =="b")
echo"<p>Customer referred by TV advert. </p>";
elseif($find=="c")
echo"<p>Customer referred by phone directory. </p>";
elseif($find=="d")
echo "<p> Customer referred by word of mouth. </p>";
$outputstring = $date."\t".$tireqty." tires \t".$oilqty." oil\t"
.$sparkqty." spark plugs\t\$".$totalamount
."\t". $address."\n";
// open file for appending
@ $fp = fopen("$DOCUMENT_ROOT/webshop/orders/orders.txt", 'ab');
flock($fp, LOCK_EX);
if (!$fp) {
echo "<p><strong> Your order could not be processed at this time.
Please try again later.</strong></p></body></html>";
exit;
}
fwrite($fp, $outputstring, strlen($outputstring));
flock($fp, LOCK_UN);
fclose($fp);
echo "<p>Order written.</p>";
?>
</body>
</html>
//create short variable names
$tireqty = $_POST['tireqty'];
$oilqty = $_POST['oilqty'];
$sparkqty = $_POST['sparkqty'];
$address = $_POST['address'];
$find = $_POST['find'];
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
$date = date('H:i; jS F Y');
?>
<html>
<head>
<title>Bob's Auto parts - Order Results</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Order Results</h2>
<?php
echo "<p>Order processed at ";
echo date("H:i, jS F");
echo "<br>";
echo "<p>Your order is as follows: </p>";
$totalqty = 0;
$totalqty = $tireqty + $oilqty + $sparkqty;
if ($totalqty == 0) {
echo "You did not order anything on the previous page!<br />";
} else {
if ($tireqty > 0) {
echo $tireqty." tires<br />";
}
if ($oilqty > 0) {
echo $oilqty." bottle(s) of oil<br />";
}
if ($sparkqty > 0) {
echo $sparkqty." Spark Plugs<br />";
}
}
$totalamount = 0.00;
define('TIREPRICE', 100);
define('OILPRICE', 10);
define('SPARKPRICE', 4);
$totalamount = $tireqty * TIREPRICE
+ $oilqty * OILPRICE
+ $sparkqty * SPARKPRICE;
$totalamount=number_format($totalamount, 2);
echo "<br>\n";
echo "Items ordered: ".$totalqty."<br />\n";
echo "Subtotal: $".$totalamount."<br />\n";
$taxrate =0.10; //local salestax is 10%
$totalamount = $totalamount + ($totalamount * $taxrate);
$totalamount=number_format($totalamount, 2);
echo "Total including tax: $".$totalamount."<br />\n";
echo "<p>Address to ship to is ".$address."</p>";
if($find == "a")
echo "<p>Regular customer. </p>";
elseif($find =="b")
echo"<p>Customer referred by TV advert. </p>";
elseif($find=="c")
echo"<p>Customer referred by phone directory. </p>";
elseif($find=="d")
echo "<p> Customer referred by word of mouth. </p>";
$outputstring = $date."\t".$tireqty." tires \t".$oilqty." oil\t"
.$sparkqty." spark plugs\t\$".$totalamount
."\t". $address."\n";
// open file for appending
@ $fp = fopen("$DOCUMENT_ROOT/webshop/orders/orders.txt", 'ab');
flock($fp, LOCK_EX);
if (!$fp) {
echo "<p><strong> Your order could not be processed at this time.
Please try again later.</strong></p></body></html>";
exit;
}
fwrite($fp, $outputstring, strlen($outputstring));
flock($fp, LOCK_UN);
fclose($fp);
echo "<p>Order written.</p>";
?>
</body>
</html>
als ik van alles 1 neem dan klopt de prijsberekening wel maar van zodra ik de aantallen ga vermeerderen klopt de prijsberekening niet meer wat doe ik verkeerd?
stukje gerelateerde code
Code (php)
1
2
3
4
5
6
7
2
3
4
5
6
7
echo "Items ordered: ".$totalqty."<br />\n";
echo "Subtotal: $".$totalamount."<br />\n";
$taxrate =0.10; //local salestax is 10%
$totalamount = $totalamount + ($totalamount * $taxrate);
$totalamount=number_format($totalamount, 2);
echo "Total including tax: $".$totalamount."<br />\n";
echo "<p>Address to ship to is ".$address."</p>";
echo "Subtotal: $".$totalamount."<br />\n";
$taxrate =0.10; //local salestax is 10%
$totalamount = $totalamount + ($totalamount * $taxrate);
$totalamount=number_format($totalamount, 2);
echo "Total including tax: $".$totalamount."<br />\n";
echo "<p>Address to ship to is ".$address."</p>";
alvast bedankt voor jullie hulp
var_dump() om te kijken wat er in iedere variabele zit die iets met $totalamount te maken heeft.
Oftewel je totalamount is fout? Gebruik eens strval().
Kijk eens naar Gewijzigd op 01/01/1970 01:00:00 door - SanThe -
neen die is goed, maar het gaat fout op de tax berekening daar krijg ik dan het resultaat1.10 zodra ik meerdere items heb "gekocht"