Jump to content

Verifying Value


ImJustBrndn

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.