jetlife76 Posted October 10, 2011 Share Posted October 10, 2011 Ok here's my issue, im trying to create a program that will calculate the total cost of an item, tax, shipping and shipping date, so far i've ran into a problem setting up my "If" statement with the perameters needed to calculate the shipping cost, Here's the code i have so far: <?php $Cost = $_POST['fielda']; $Tax = ($Cost * .06); $Sub = ($Cost + $Tax); $Ship = $Total = ($Cost + $Tax + $Ship); if ( $Sub <= 25.99 ){ print "$Ship: 3.00<br>"; } elseif ($Sub >= 26.00 || <= 50.99 ){ print "$Ship: 4.00<br>";} elseif ($Sub >= 51.00 || <= 75.00) { print "$Ship: 5.00<br>";} elseif ($Sub > 75.00) { print "Ship: 6.00<br>";} else { print ("Cost : $Cost<br> Tax: $Tax<br> Shippingtotal is $$Total");} ?> Here's the error i keep getting: Parse error: syntax error, unexpected T_IS_SMALLER_OR_EQUAL in C:\wamp\ on line 16 any help i can get will be greatly appreciated, I also need to know how to do the shipping date (15 days) as well if you can help with that as well Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted October 10, 2011 Share Posted October 10, 2011 You need to repeat your variable for each test, e.g.: elseif ($Sub >= 26.00 || $Sub <= 50.99 ){ Quote Link to comment Share on other sites More sharing options...
jetlife76 Posted October 10, 2011 Author Share Posted October 10, 2011 Ok yea that was helpful, total brain freeze, but now im lost on how to define my variable for $Ship and should i have a seperate print statement to show the cost- tax-shipping & total amount? Quote Link to comment Share on other sites More sharing options...
darkspire Posted October 10, 2011 Share Posted October 10, 2011 try this: <?php $Cost = $_POST['fielda']; $Tax = ($Cost * .06); $Sub = ($Cost + $Tax); $Ship = 0; if ( $Sub <= 25.99 ){ $Ship= 3.00; } elseif ($Sub >= 26.00 || $Sub <= 50.99 ){ $Ship= 4.00; } elseif ($Sub >= 51.00 || $Sub <= 75.00) { $Ship: 5.00; } elseif ($Sub > 75.00) { $Ship= 6.00; } $Total = ($Cost + $Tax + $Ship); print ("Cost : $Cost<br> Tax: $Tax<br> Ship: $Ship<br> Shipping total is $Total");} ?> Quote Link to comment Share on other sites More sharing options...
jetlife76 Posted October 10, 2011 Author Share Posted October 10, 2011 ok cool that seems to work, but when i put in a value larger than 50 it only gives me a 4.00 shipping when it should be 5 or 6 Quote Link to comment Share on other sites More sharing options...
darkspire Posted October 10, 2011 Share Posted October 10, 2011 its a logic error... take out the elseif's and use && instead of ||. that should fix it. <?php $Cost = $_POST['fielda']; $Tax = ($Cost * .06); $Sub = ($Cost + $Tax); if ( $Sub <= 25.99 ) $Ship= 3.00; if ($Sub >= 26.00 && $Sub <= 50.99 ) $Ship= 4.00; if ($Sub >= 51.00 && $Sub <= 75.00) $Ship: 5.00; if ($Sub > 75.00) $Ship= 6.00; $Total = ($Cost + $Tax + $Ship); print ("Cost : $Cost<br> Tax: $Tax<br> Ship: $Ship<br> Shipping total is $Total"); ?> Quote Link to comment Share on other sites More sharing options...
jcbones Posted October 10, 2011 Share Posted October 10, 2011 Or, you could build it in reverse. <?php $Cost = $_POST['fielda']; $Tax = ($Cost * .06); $Sub = ($Cost + $Tax); if ( $Sub > 75.00 ) $Ship= 6.00; elseif ($Sub > 51.00 ) $Ship= 5.00; elseif ($Sub > 26.00) $Ship: 4.00; else $Ship= 3.00; $Total = ($Cost + $Tax + $Ship); print ("Cost : $Cost<br> Tax: $Tax<br> Ship: $Ship<br> Shipping total is $Total"); ?> Quote Link to comment Share on other sites More sharing options...
jetlife76 Posted October 10, 2011 Author Share Posted October 10, 2011 ok cool thanks, one more thing then i'll be good to go from here, im trying to also show the shipping date which is 15 days after the order date would i use the timestamp, "$ShipDate = mktime(0,0,0,date("m"),date("d")+1,date("Y"));" but im only getting a list of numbers i want it to show the month spelled out, the day, year How do i set the current date as well, last question and i swear im done Thanks in advance Quote Link to comment Share on other sites More sharing options...
darkspire Posted October 10, 2011 Share Posted October 10, 2011 $date1 = date(‘Y-m-d’); $date2 = “2007-02-26″; $days = (strtotime($date1) – strtotime($date2)) / (60 * 60 * 24); echo ” No of $days difference”; Quote Link to comment Share on other sites More sharing options...
jcbones Posted October 10, 2011 Share Posted October 10, 2011 I would use: <?php $currentDate = date('Y-m-d'); $shippingDate = date('Y-m-d',strtotime('+ 15 days')); Quote Link to comment Share on other sites More sharing options...
jetlife76 Posted October 10, 2011 Author Share Posted October 10, 2011 Hey you guys are the best man!!! I thank you all for your help!!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.