Jump to content

Archived

This topic is now archived and is closed to further replies.

ImJustBrndn

Verifying Value

Recommended Posts

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

Share this post


Link to post
Share on other sites
[code]if($coupon == "monkey"){ ... }[/code]

You need the quotes around monkey. Unless monkey is a constant of course.

Share this post


Link to post
Share on other sites
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']. 

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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'];

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.