Hey everyone, I am encountering a problem with $_POST[]; here goes my code: <?php // create short variable names $tireqty = $_POST['5']; $oilqty = $_POST['10']; $sparkqty = $_POST['90']; $find = $_POST['find']; ?> <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 ".date('H:i, jS F Y')."</p>"; echo "<p>Your order is as follows: </p>"; $totalqty = 0; $totalqty = $tireqty + $oilqty + $sparkqty; echo "Items ordered: ".$totalqty."<br />"; 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." bottles 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; echo "Subtotal: $".number_format($totalamount,2)."<br />"; $taxrate = 0.10; // local sales tax is 10% $totalamount = $totalamount * (1 + $taxrate); echo "Total including tax: $".number_format($totalamount,2)."<br />"; 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>"; } else { echo "<p>We do not know how this customer found us.</p>"; } ?> </body> </html> When I go to preview the result my HTML comes up like this: Bob's Auto Parts Order Results Order processed at 23:29, 17th July 2012 Your order is as follows: Items ordered: 0 You did not order anything on the previous page! Subtotal: $0.00 Total including tax: $0.00 We do not know how this customer found us. PS: register_globals is turned on.
Can you provide all of the code? Because in your HTML form, you're going to need to set the name attribute for every input element that you plan to catch with $_POST.
Basically I don't have the HTML yet, I am running the tests by manually altering the code and previewing in my browser... and nothing happens. :-(
well you should recheck to see if all your symbols are placed correctly and whats your method of manual altering and testing?
It would help if you actually told us what your problems are. You should also always check that keys in an array exists before using them: if(array_key_exists("key", $_POST)) { $var = $_POST["key"]; } Code (markup): Otherwise you will get an "undeclared index" error if they don't exist. My first advice would be to do some white-box testing, have you tried printing/echoing the post values to make sure that they're even set? What does this mean? You can't directly set values within the global $_POST variable. You have to use an HTTP post request either through an HTML form or with cURL. I just realised something, why is such a large index being used with $_POST? I hope you don't think that $_POST['90'] sets anything to 90... I think you should go back to basics and learn what arrays are and what they do. Why do you have an integer within quotes? You're also converting 90 into a string!