discount voucher how to set up using php

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

User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: discount voucher how to set up using php

Post by Christopher »

jonnyfortis wrote:i changed the html document
You need to change the character set used by that database table/field. I assume that the HTML encoding was working OK previously.
jonnyfortis wrote:the only code above this is

Code: Select all

<?php require_once('Connections/lotties.php'); ?>
<?php
// do not cache
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    	        // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header ("Cache-Control: no-cache, must-revalidate");  	        // HTTP/1.1
header ("Pragma: no-cache");    
There is a return character(s) between you two PHP blocks in the above code. Any output (including whitespace characters) will cause PHP to automatically send headers. I'd recommend merging that code into on PHP block.
(#10850)
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: discount voucher how to set up using php

Post by jonnyfortis »

Christopher wrote:There is a return character(s) between you two PHP blocks in the above code. Any output (including whitespace characters) will cause PHP to automatically send headers. I'd recommend merging that code into on PHP block
i have changed to

Code: Select all

<?php require_once('Connections/lotties.php');

header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    	        // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header ("Cache-Control: no-cache, must-revalidate");  	        // HTTP/1.1
header ("Pragma: no-cache");        

if (!function_exists("GetSQLValueString")) {
but still getting the same warning
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: discount voucher how to set up using php

Post by jonnyfortis »

Christopher wrote:
jonnyfortis wrote:i changed the html document
You need to change the character set used by that database table/field. I assume that the HTML encoding was working OK previously.
jonnyfortis wrote:the only code above this is

Code: Select all

<?php require_once('Connections/lotties.php'); ?>
<?php
// do not cache
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    	        // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header ("Cache-Control: no-cache, must-revalidate");  	        // HTTP/1.1
header ("Pragma: no-cache");    
There is a return character(s) between you two PHP blocks in the above code. Any output (including whitespace characters) will cause PHP to automatically send headers. I'd recommend merging that code into on PHP block.

>>>You need to change the character set used by that database table/field. I assume that the HTML encoding was working OK previously.

do you mean chnage the Collation setting? but i dont know what column this needs to be changed in
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: discount voucher how to set up using php

Post by Christopher »

I am confused that you are confused. You need to get the character encoding the same for $_POST['vouchCode'] and $row_rsVoucher['VCode']; The values were lot123£10 and lot123�10 which due to encoding do not match. So the encoding of the form data and the encoding of the field that populates the $row_rsVoucher['VCode'] variable.
(#10850)
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: discount voucher how to set up using php

Post by jonnyfortis »

Christopher wrote:I am confused that you are confused. You need to get the character encoding the same for $_POST['vouchCode'] and $row_rsVoucher['VCode']; The values were lot123£10 and lot123�10 which due to encoding do not match. So the encoding of the form data and the encoding of the field that populates the $row_rsVoucher['VCode'] variable.
oh sorry i see what you mean, i will try that then, thanks
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: discount voucher how to set up using php

Post by jonnyfortis »

ok i have now sorted the encoding out i have not included the BOM and i have also changed the £ sign for the letter "p" and the % sign for "c" this way its no special characters just letters and numbers.

i have also changed the Database values to read

lot123p5 ( this is £5 off )
or
lot123f10 ( this 10% off )

and the php code to match this

Code: Select all

// voucher code
if (isset($_POST['vouchCode']) && $_POST['vouchCode'] == $row_rsVoucher['VCode']) {
  $mycode = $row_rsVoucher['VCode'];
  $spos = strpos($mycode, "f");
  if ($spos !== false) {
    $myvalue = substr($mycode, $spos+1);
    $myvalue = $XCart_sumTotal * $myvalue / 100;
  } else {
    $spos = strpos($mycode, "p");
    if ($spos !== false) {
      $myvalue = substr($mycode, $spos+1);
    }
  }
  $myTotal = $XCart_sumTotal - $myvalue;
  $_SESSION['vouchCode'] = $myvalue;
} else unset($_SESSION['vouchCode']);

function DoFormatCurrency($num,$dec,$sdec,$sgrp,$sym,$cnt) {
  setlocale(LC_MONETARY, $cnt);
  if ($sdec == "C") {
    $locale_info = localeconv();
    $sdec = $locale_info["mon_decimal_point"];
    $sgrp = $sgrp!="" ? $locale_info["mon_thousands_sep"] : "";
    $sym = $cnt!="" ? $locale_info["currency_symbol"] : $sym;
  }
  $thenum = $sym.number_format($num,$dec,$sdec,$sgrp);
  return $thenum;
}

what is happening is i have echoed out

Code: Select all

<?php echo $myvalue ?><br />
            <?php echo $_POST['vouchCode']; ?><br />
           <?php echo $row_rsVoucher['VCode']; ?> <br />
the <?php echo $row_rsVoucher['VCode']; ?> is always showing the lot123p5 which is the first record on the DB

when i submit the value lot123p5 i get the following

<?php echo $myvalue ?> shows 5
<?php echo $_POST['vouchCode']; ?> shows lot123p5
and <?php echo $row_rsVoucher['VCode']; ?> shows lot123p5

so thats working

when i try the percentage and submit lot123f10 i get the following

<?php echo $myvalue ?> shows nothing
<?php echo $_POST['vouchCode']; ?> shows lot123f10
and <?php echo $row_rsVoucher['VCode']; ?> shows lot123p5

and therefor isnt working

i have added another discount code to the £ discount to see if it was the % thing

lottiep3

to show £3 discount but that isnt working either so it must only be working for the first record in the DB
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: discount voucher how to set up using php

Post by jonnyfortis »

i am pretty desperate to get this issue resolved, can anyone advise me what i need to do to get this working

thanks in advance
Post Reply