Jump to content


Photo

Verifying Value


  • Please log in to reply
6 replies to this topic

#1 ImJustBrndn

ImJustBrndn
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 15 September 2006 - 05:44 PM

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.

<?php
	  
	   	if ($coupon == monkey) {

	$finalvalue = $totalvalue - 3.00;
			
} else {
	
	echo "<td colspan=\"5\"><center><p>Unknown Coupon</p></center></td>";

}
	?>

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

#2 bholbrook

bholbrook
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 15 September 2006 - 06:12 PM

if($coupon == "monkey"){ ... }

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

#3 Wintergreen

Wintergreen
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts

Posted 15 September 2006 - 06:14 PM

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']. 

#4 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 15 September 2006 - 06:18 PM

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

#5 ImJustBrndn

ImJustBrndn
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 16 September 2006 - 01:32 AM

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.

<?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>


#6 Wintergreen

Wintergreen
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts

Posted 16 September 2006 - 01:50 AM

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'];

#7 ImJustBrndn

ImJustBrndn
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 16 September 2006 - 07:20 AM

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....

<?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>";

}
	?>

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users