ImJustBrndn Posted September 15, 2006 Share Posted September 15, 2006 I have a shopping cart system set up, and It forwards a few values such as the total from the cart -> shipping info -> verify -> paypal.I was wondering if there was anyway for me to put a form field on the shipping info page called "coupon" and then on the verify page have a statement like if coupon = pizza $totalvalue - 3.00 or something like that. Is that possible so that way if they put in a coupon code that I specify it will take off a specific amount, I've been trying to do this but it keeps giving me errors.[code]<?php if ($coupon == monkey) { $finalvalue = $totalvalue - 3.00; } else { echo "<td colspan=\"5\"><center><p>Unknown Coupon</p></center></td>";} ?>[/code]That's what I have probably not right. The field from the previous page being forwarded to this page is called "coupon". Thanks in advance.Brandon Quote Link to comment Share on other sites More sharing options...
bholbrook Posted September 15, 2006 Share Posted September 15, 2006 [code]if($coupon == "monkey"){ ... }[/code]You need the quotes around monkey. Unless monkey is a constant of course. Quote Link to comment Share on other sites More sharing options...
Wintergreen Posted September 15, 2006 Share Posted September 15, 2006 Post your errors, that helps us know what to look for. For starters, I think if you're comparing a variable to a string you need to put it in quotes, either '' or "", so try putting monkey in quotes. Other than that, from what I see there you're not accessing any data from anywhere. If you're using forms and the method is post, you use the value from the form by $_POST['variable_name']. Quote Link to comment Share on other sites More sharing options...
craygo Posted September 15, 2006 Share Posted September 15, 2006 I would also put all your coupons in their own table. That way you are not writing php code for every coupon you want to add. If you hold it in the database you can put the name and the value then have it search for it and return the discount then.Ray Quote Link to comment Share on other sites More sharing options...
ImJustBrndn Posted September 16, 2006 Author Share Posted September 16, 2006 OK, With your help I've come up with this, but I'm still getting an echo error on the two echo commands featured in the code. I would love to store the codes in the database and pull them out, but I wouldn't even know where to begin with any of that.[code]<?php $coupon = echo $_POST['coupon']; $totalvalue = echo $_POST["totalvalue"]; if ($coupon == "monkey") { $finalvalue = $totalvalue - 3.00; } else { echo "<td colspan=\"5\"><center><p>Unknown Coupon</p></center></td>";} ?></p>[/code] Quote Link to comment Share on other sites More sharing options...
Wintergreen Posted September 16, 2006 Share Posted September 16, 2006 You only use echo when you want something displayed on the screen. When you're declaring a new variable and making it equal to the post ones, you just do variable = $_POST['whatever']; Quote Link to comment Share on other sites More sharing options...
ImJustBrndn Posted September 16, 2006 Author Share Posted September 16, 2006 Thanks for all the great help, I'm almost there just having one slight problem. It now does the calculations as it should if someone inputs the code, but it only shows the finalvalue of being -3....[code]<?php $coupon = $_POST['coupon']; $totalvalue = $_POST['totalvalue']; if ($coupon == "monkey") { $finalvalue = $totalvalue - 3.00; } else { echo "<td colspan=\"5\"><center><p>Unknown Coupon</p></center></td>";} ?>[/code]The $finalvalue = $totalvalue - 3.00; the $totalvalue isn't displaying the forwarded value from the previous page in the formula, but if I echo it, it shows the value just fine, why won't it do it in the formula? Thanks again.Brandon 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.