maria Posted March 11, 2009 Report Share Posted March 11, 2009 Hi There, Following Jon's video tutorial I am trying to add shipping method to my cart(instead of using paypal I would rather have the order emailed to myself and the visitor). If the total is $100 + they get free delivery, however, if it is less, they get a different option. I used if - else statement but it threw me an error. Can anyone take a look at my code and see where I messed up? Thanks, Maria <? if($cart) { ?> (X)ItemSizeQuantityUnit PriceItem Subtotal <? $keys = array_keys($cart); foreach($keys as $key) { $array = explode(".", $key); $name = $array[0]; $size = $array[1]; $quantity = $cart["$key"]; $price = $xml->xpath("//item[@name=$name]/price[@size=$size]"); $unitPrice = (float) $price[0]; $itemSubtotal = $unitPrice * $quantity; $total = $total + $itemSubtotal; ?> remove <? print($name); ?> <? print($size); ?> <? print($quantity); ?> $<? printf("%0.2f", $unitPrice); ?> $<? printf("%0.2f", $itemSubtotal); ?> <? } ?> Total: $<? printf("%0.2f", $total); ?> <? ?> <? } else { ?> Your cart is empty! <? } ?> Quote Link to comment Share on other sites More sharing options...
falkencreative Posted March 11, 2009 Report Share Posted March 11, 2009 I'm not seeing any if statement in your above code, besides "if($cart)". Can you point it out, or post the bit of code that includes the areas you are having trouble with? Posting the actual error might help as well. Quote Link to comment Share on other sites More sharing options...
maria Posted March 11, 2009 Author Report Share Posted March 11, 2009 Thanks for looking up quickly. Here's the error: Parse error: syntax error, unexpected T_DOUBLE_ARROW in /Applications/xampp/xamppfiles/htdocs/XML/p7c/cart2.php on line 89 Also, I just copied that statement "if($cart) {...} else {print "Your Cart is empty!}" somewhere that I don't remember now. Is that where the problem could be? I am repasting the code where I added the if and else statement that didn't work. If the total is equal to or more than $100, it should take them to the delivery page, but if not, then to pick-up page. Or is there any better alternative? I really appreciate your help. Maria ----- <? $xml = new SimpleXMLElement(file_get_contents("store.xml")); session_start(); $cart = $_SESSION["cart"]; ?> <? require_once("head.php"); ?> <? if($cart) { ?> (X)ItemSizeQuantityUnit PriceItem Subtotal <? $keys = array_keys($cart); foreach($keys as $key) { $array = explode(".", $key); $name = $array[0]; $size = $array[1]; $quantity = $cart["$key"]; $price = $xml->xpath("//item[@name=$name]/price[@size=$size]"); $unitPrice = (float) $price[0]; $itemSubtotal = $unitPrice * $quantity; $total = $total + $itemSubtotal; ?> remove <? print($name); ?> <? print($size); ?> <? print($quantity); ?> $<? printf("%0.2f", $unitPrice); ?> $<? printf("%0.2f", $itemSubtotal); ?> <? } ?> Total: $<? printf("%0.2f", $total); ?> <? ?> <? } else { ?> Your cart is empty! <? } ?> <? if ($total=>100) { header ('Location: Delivery.php'); } else { header ('Location: pickUp.php'); } ?> Go Back to Shopping <? require_once("end.php"); ?> Quote Link to comment Share on other sites More sharing options...
falkencreative Posted March 12, 2009 Report Share Posted March 12, 2009 the issue seems like it is with this "=>" in your if statement. It needs to be this instead: ">=". However, I'm guessing that fixing this error will then lead to a "headers already sent" error. To be honest, I am not totally sure what you are trying to do here... according to your above code, it would display part of the cart page, and then immediately redirect them to either the delivery or pickup page based on their order total. The visitor wouldn't even see the card page. Wouldn't you want to redirect them after they click the "checkout" button? Quote Link to comment Share on other sites More sharing options...
maria Posted March 12, 2009 Author Report Share Posted March 12, 2009 Hi Benjamin, When you said: Wouldn't you want to redirect them after they click the "checkout" button? Yes, that's what I really wanted to do, I just could not figure out how to say it right. I always want the visitor to see the cart page all the time. Would you suggest that I should create another checkout page with all same info where all these things happen? Then I'll try the ">=". and see what happens. Many thanks, Maria 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.
Note: Your post will require moderator approval before it will be visible.