/home/wpollock1/public_html/PHP/processorder.php.txt
1: <?php
2: // create short variable names
3: $tireqty = $_POST['tireqty'];
4: $oilqty = $_POST['oilqty'];
5: $sparkqty = $_POST['sparkqty'];
6: $address = $_POST['address'];
7:
8: $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
9: ?>
10: <html>
11: <head>
12: <title>Bob's Auto Parts - Order Results</title>
13: </head>
14: <body>
15: <h1>Bob's Auto Parts</h1>
16: <h2>Order Results</h2>
17: <?php
18: date_default_timezone_set('America/New_York');
19: $date = date('H:i, jS F');
20:
21: echo '<p>Order processed at ';
22: echo $date;
23: echo '</p>';
24:
25: echo '<p>Your order is as follows: </p>';
26:
27: $totalqty = 0;
28: $totalqty = $tireqty + $oilqty + $sparkqty;
29: echo 'Items ordered: '.$totalqty.'<br />';
30:
31: if( $totalqty == 0)
32: {
33: echo 'You did not order anything on the previous page!<br />';
34: }
35: else
36: {
37: if ( $tireqty>0 )
38: echo $tireqty.' tires<br />';
39: if ( $oilqty>0 )
40: echo $oilqty.' bottles of oil<br />';
41: if ( $sparkqty>0 )
42: echo $sparkqty.' spark plugs<br />';
43: }
44:
45: $totalamount = 0.00;
46:
47: define('TIREPRICE', 100);
48: define('OILPRICE', 10);
49: define('SPARKPRICE', 4);
50:
51: $totalamount = $tireqty * TIREPRICE
52: + $oilqty * OILPRICE
53: + $sparkqty * SPARKPRICE;
54:
55: $totalamount=number_format($totalamount, 2, '.', ' ');
56:
57: echo '<p>Total of order is '.$totalamount.'</p>';
58: echo '<p>Address to ship to is '.$address.'</p>';
59:
60: $outputstring = $date."\t".$tireqty." tires \t".$oilqty." oil\t"
61: .$sparkqty." spark plugs\t\$".$totalamount
62: ."\t". $address."\n";
63:
64: // As this script is on the web, I don't want anyone to actually
65: // use it:
66: if ( FALSE ) {
67:
68: // open file for appending
69: $fp = fopen("$DOCUMENT_ROOT/PHP/orders.txt", 'ab');
70:
71:
72:
73: if (!$fp)
74: {
75: echo '<p><strong> Your order could not be processed at this time. '
76: .'Please try again later.</strong></p></body></html>';
77: exit;
78: }
79:
80: fwrite($fp, $outputstring, strlen($outputstring));
81:
82: fclose($fp);
83: }
84:
85: echo '<p>Order written. (Not really)</p>';
86: ?>
87:
88: </body>
89: </html>