Discount

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
YoussefSiblini
Forum Contributor
Posts: 206
Joined: Thu Jul 21, 2011 1:51 pm

Discount

Post by YoussefSiblini »

Hi Guys,

I want to take 20% off from my price, every thing is working fine, but if the user keep adding the voucher number it keep taking 20% off again, I want it when it take 20% once to not allow again, how can I achieve this?
HTML:

Code: Select all

<form name="form1" action="test1.php" method="post">
    <input class="Voucher_TextBox" name="Voucher_TextBox" type="text" value="Voucher Number"/>
    <input type="submit" name="CheckVoucher" value="Add Voucher">
</form>
PHP:

Code: Select all

	if (isset($_POST['CheckVoucher'])) 
	{ 
	    $Voucher_TextBox = $_POST['Voucher_TextBox'];
	    if($Voucher_TextBox == 1234)
		{
			$discount = 0.20; // 20% discount
			$price = number_format($price * (1 - $discount), 2); // be sure to have only 2 numbers after the point like: 65.95
			$TotalPrice = number_format($price + $shipping, 2); // Get the total price with shipping after the 20% discount.
			$total = str_replace('.', '', $TotalPrice); // get rude of the point
			
			$voucherOutput = '20% has been taken off from the item price';
		}
		else
		{
			$voucherOutput =
			'
				<div id="HSBCBuy_Form_Div">
				   <div class="Dark_Red_Color">The Voucher number you entered is wrong, please insert a correct voucher number.</div>
				   <div class="Grey_Color">Make sure that you selected the right country from the countries drop list.</div>
				</div>
			';
		}
	}

Many thanks,


Jo
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Discount

Post by social_experiment »

YoussefSiblini wrote:I want it when it take 20% once to not allow again, how can I achieve this?
You'd want to store the presence of a voucher somewhere; so if someone does use a voucher, set some type of value, either in a database or maybe in a session?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
YoussefSiblini
Forum Contributor
Posts: 206
Joined: Thu Jul 21, 2011 1:51 pm

Re: Discount

Post by YoussefSiblini »

Thank you,
I will use sessions.
Post Reply