system32 Posted March 13, 2010 Share Posted March 13, 2010 Hello. I am currently learning PHP and have been working on this exercise. I want to to calculate the total order amount and add the provincial sales tax to it. For some reason almost every time I calculate the total amount it is always using the 13% sales tax. What am I doing wrong? Any help would be greatly appreciated. This is my code: HTML: <html> <head> <script language="javascript" type="text/javascript"> function checkForm() { var errMessage = ""; var myForm = document.orderForm; if (myForm.firstName.value == "") { errMessage += "\nPlease enter your first name"; } if (myForm.lastName.value == "") { errMessage += "\nPlease enter your last name"; } if (myForm.address.value == "") { errMessage += "\nPlease enter a valid address"; } if (myForm.city.value == "") { errMessage += "\nPlease enter a valid city"; } if (myForm.province.value == "one") { errMessage += "\nPlease select a province"; } if (myForm.postalCode.value == "") { errMessage += "\nPlease enter a valid postal code"; } if (myForm.purchaseItem.value == "") { errMessage += "\nPlease select an item to purchase"; } if (myForm.quantity.value == "") { errMessage += "\nPlease enter a quantity amount"; } if (isNaN(myForm.quantity.value)) { errMessage += "\nPlease enter a valid quantity amount"; } if (errMessage != "") { alert (errMessage); return false; } return true; } </script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form id="orderForm" name="orderForm" method="post" onSubmit="return checkForm()" action="exercise.php" > <table width="619" height="169" border="0"> <tr> <td width="94" height="26">First Name:</td> <td width="205"><label> <input name="firstName" type="text" id="firstName" /> </label></td> <td width="168">Item To Be Purchased:</td> <td width="124"><label> <select name="purchaseItem" id="purchaseItem"> <option value="">Select Item</option> <option value="video">Video Card</option> <option value="case">Computer Case</option> <option value="cpuFan">CPU Fan</option> <option value="caseFan">Case Fan</option> <option value="keyboard">Keyboard</option> <option value="mouse">Mouse</option> </select> </label></td> </tr> <tr> <td height="26">Last Name:</td> <td><label> <input type="text" name="lastName" id="lastName" /> </label></td> <td>Quantity:</td> <td><label> <input name="quantity" type="text" id="quantity" maxlength="3" /> </label></td> </tr> <tr> <td height="26">Address:</td> <td><input type="text" name="address" id="address" /></td> <td>Extra:</td> <td><label> <input type="checkbox" name="ram" id="ram" /> RAM<br /> <input type="checkbox" name="cpu" id="cpu" /> CPU <br /> </label></td> </tr> <tr> <td height="26">City:</td> <td><label> <input type="text" name="city" id="city" /> </label></td> <td> </td> <td> </td> </tr> <tr> <td height="26">Province:</td> <td><label> <select name="province" id="province"> <option value="one">Please Select a Province</option> <option value="AB">Alberta</option> <option value="BC">British Columbia</option> <option value="MB">Manitoba</option> <option value="NB">New Brunswick</option> <option value="NL">Newfoundland and Labrador</option> <option value="NWT">Northwest Territories</option> <option value="NS">Nova Scotia</option> <option value="NU">Nunavut</option> <option value="ON">Ontario</option> <option value="PEI">Prince Edward Island</option> <option value="QC">Quebec</option> <option value="SK">Saskatchewan</option> <option value="YT">Yukon</option> </select> </label></td> <td> </td> <td> </td> </tr> <tr> <td height="23">Postal Code:</td> <td><label> <input type="text" name="postalCode" id="postalCode" /> </label></td> <td><label> <div align="center"> <input type="reset" name="reset" id="reset" value="Reset" /> </div> </label></td> <td><label> <input type="submit" name="submit" id="submit" value="submit"/> </label></td> </tr> </table> </form> </body> </html> PHP: <?php $firstName = $_POST["firstName"]; $lastName = $_POST["lastName"]; $address = $_POST["address"]; $city = $_POST["city"]; $province = $_POST["province"]; $postalCode = $_POST["postalCode"]; $item = $_POST["purchaseItem"]; $quantity = $_POST["quantity"]; $operatingSystem = $_POST["operatingSystem"]; $itemCost; $salesTax; $shippingCharge; $delivery; print ("<br> <br>"); print ("Shipping To: $lastName, $firstName <br>"); print ("$address <br>"); print ("$city, $province <br>"); print ("$postalCode <br>"); print ("<br> <br>"); if ($item == "video") { $itemCost = 350; } elseif ($item == "case") { $itemCost = 55; } elseif ($item == "cpuFan") { $itemCost = 18; } elseif ($item == "caseFan") { $itemCost = 12; } elseif ($item == "keyboard") { $itemCost = 28; } else { $itemCost = 14; } if ($province == "AB") { $salesTax = 0.05; } elseif ($province == "BC") { $salesTax = 0.12; } elseif ($province == "MB") { $salesTax = 0.12; } elseif ($province == "NB") { $salesTax = 0.13; } elseif ($province == "NL") { $salesTax = 0.13; } elseif ($province == "NS") { $salesTax = 0.13; } elseif ($province = "ON") { $salesTax = 0.13; } elseif ($province = "PEI") { $salesTax = 0.155; } elseif ($province = "QC") { $salesTax = 0.12875; } elseif ($province = "SK") { $salesTax = 0.10; } else { $salesTax = 0; } $totalItemCost = ($itemCost * $quantity); $totalTaxItem = ($totalItemCost * $salesTax) + $totalItemCost; if ($totalTaxItem <= 25) { $shippingCharge = 3; $delivery = 1; } elseif ($totalTaxItem > 25 && $totalTaxItem <= 50) { $shippingCharge = 4; $delivery = 1; } elseif ($totalTaxItem > 50 && $totalTaxItem <= 75) { $shippingCharge = 5; $delivery = 3; } else { $shippingCharge = 6; $delivery = 4; } $totalOrderCost = $totalTaxItem + $shippingCharge; $totalSaleTax = $salesTax * 100; print ("Order Information: <br>"); print ("Item Cost: $$itemCost <br>"); print ("Quantity: $quantity <br>"); print ("Tax: $totalSaleTax %<br>"); print ("Delivery Charge: $$shippingCharge <br>"); print ("Total Order Is: $$totalOrderCost <br>"); print ("Shipping: $delivery buisness day(s) <br>"); ?> Link to comment https://forums.phpfreaks.com/topic/195140-problem-with-php-same-value-always-showing-up/ Share on other sites More sharing options...
system32 Posted March 13, 2010 Author Share Posted March 13, 2010 I found the problem. Please disregard this post Link to comment https://forums.phpfreaks.com/topic/195140-problem-with-php-same-value-always-showing-up/#findComment-1025710 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.