Discount Codes

Fatal Error - Discount Codes

Fatal Error

by radhavallabh » Wed Jun 08, 2022 5:37 am

Hi dear;
I am using 1.0.8.15
When I input a discount code on checkout_payment.php
It always shows that Discount is invalid.
On further debugging I checked the Network tab of Console
The discount_code.php gives fatal error while performing xhr
Fatal error</b>: DB: [1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@xx.com
AND customers_guest = '1')' at line 3 from <SELECT count(*) AS orders
FROM orders
WHERE customers_email_address = xx@xx.com
AND customers_guest = '1');> in <b>/xx/includes/system/versioned/1.0.8.1/database_core.php</b> on line <b>44</b><br />

Also I would like to mention that I do have PWA installed- but I tried adding a discount code with a registered account.

Please can you help fix the error dear;
Thank you in advance;
Regds./
radhavallabh
radhavallabh
VIP Member
VIP Member
Posts: 369
Joined: Tue Oct 27, 2020 4:09 am
Contact:

Re: Fatal Error

by raiwa » Wed Jun 08, 2022 3:10 pm

in includes/modules/order_total/ot_discount.php line 129
change:

Code: Select all

    AND customers_guest = '1');
to:

Code: Select all

    AND customers_guest = 1
Please confirm and I'll update the module.
Public Phoenix Change Log Cheat Set on Google Sheets
https://docs.google.com/spreadsheets/d/ ... sp=sharing

Need Help?viewtopic.php?f=10&t=27
raiwa
PhoenixCart Developer
PhoenixCart Developer
Posts: 1212
Joined: Sat Dec 21, 2019 8:08 am
Contact:

Re: Fatal Error

by radhavallabh » Thu Jun 09, 2022 8:49 am

raiwa wrote:in includes/modules/order_total/ot_discount.php line 129
change:

Code: Select all

    AND customers_guest = '1');
to:

Code: Select all

    AND customers_guest = 1
Please confirm and I'll update the module.
Hi dear;
Error still same error persists...
this time just it changes from '1' to 1
Fatal error: DB: [1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@xx.com AND customers_guest = 1)' at line 3 from....

Warm Regds./
radhavallabh
radhavallabh
VIP Member
VIP Member
Posts: 369
Joined: Tue Oct 27, 2020 4:09 am
Contact:

Re: Fatal Error

by raiwa » Thu Jun 09, 2022 8:55 am

Please post your modified code
Public Phoenix Change Log Cheat Set on Google Sheets
https://docs.google.com/spreadsheets/d/ ... sp=sharing

Need Help?viewtopic.php?f=10&t=27
raiwa
PhoenixCart Developer
PhoenixCart Developer
Posts: 1212
Joined: Sat Dec 21, 2019 8:08 am
Contact:

Re: Fatal Error

by radhavallabh » Thu Jun 09, 2022 9:11 am

raiwa wrote:Please post your modified code
Hi dear;
Here it is-

Code: Select all

            	  $check_mail = $check_query_mail->fetch_assoc();
            	  if (!empty($check_mail['customers_email_address'])) {
            	    $check_query_order_guest = $db->query(sprintf(<<<'EOSQL'
SELECT count(*) AS orders
  FROM orders
  WHERE customers_email_address = %s
    AND customers_guest = 1);
EOSQL
        , $check_mail['customers_email_address']));
Regds./
radhavallabh
radhavallabh
VIP Member
VIP Member
Posts: 369
Joined: Tue Oct 27, 2020 4:09 am
Contact:

Re: Fatal Error

by raiwa » Thu Jun 09, 2022 9:32 am

you didn't apply the modification as posted.
This:

Code: Select all

    AND customers_guest = 1);
must be:

Code: Select all

    AND customers_guest = 1
Remove also the parentesis and semicolon!
Public Phoenix Change Log Cheat Set on Google Sheets
https://docs.google.com/spreadsheets/d/ ... sp=sharing

Need Help?viewtopic.php?f=10&t=27
raiwa
PhoenixCart Developer
PhoenixCart Developer
Posts: 1212
Joined: Sat Dec 21, 2019 8:08 am
Contact:

Re: Fatal Error

by radhavallabh » Thu Jun 09, 2022 10:24 am

raiwa wrote:you didn't apply the modification as posted.
This:

Code: Select all

    AND customers_guest = 1);
must be:

Code: Select all

    AND customers_guest = 1
Remove also the parentesis and semicolon!
Hi;
Sorry I did not check dear-
Now the code I used is

Code: Select all

  $check_mail = $check_query_mail->fetch_assoc();
            	  if (!empty($check_mail['customers_email_address'])) {
            	    $check_query_order_guest = $db->query(sprintf(<<<'EOSQL'
SELECT count(*) AS orders
  FROM orders
  WHERE customers_email_address = %s
    AND customers_guest = 1
EOSQL
        , $check_mail['customers_email_address']));
The error I get is

Fatal error: DB: [1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@xx.com AND customers_guest = 1' at line 3 from

Please help fix the issue dear;
Very Warm Regds./
radhavallabh
radhavallabh
VIP Member
VIP Member
Posts: 369
Joined: Tue Oct 27, 2020 4:09 am
Contact:

Re: Fatal Error

by raiwa » Thu Jun 09, 2022 10:33 am

try this:

Code: Select all

  WHERE customers_email_address = '%s'
Note: single quotes added around %s
Public Phoenix Change Log Cheat Set on Google Sheets
https://docs.google.com/spreadsheets/d/ ... sp=sharing

Need Help?viewtopic.php?f=10&t=27
raiwa
PhoenixCart Developer
PhoenixCart Developer
Posts: 1212
Joined: Sat Dec 21, 2019 8:08 am
Contact:

Re: Fatal Error

by radhavallabh » Thu Jun 09, 2022 10:57 am

raiwa wrote:try this:

Code: Select all

  WHERE customers_email_address = '%s'
Note: single quotes added around %s
Same issue dear discount code shows as invalid- Now I get a 0 as Response in console dear

Code

Code: Select all

  $check_mail = $check_query_mail->fetch_assoc();
            	  if (!empty($check_mail['customers_email_address'])) {
            	    $check_query_order_guest = $db->query(sprintf(<<<'EOSQL'
SELECT count(*) AS orders
  FROM orders
  WHERE customers_email_address = '%s'
    AND customers_guest = 1
EOSQL
radhavallabh
VIP Member
VIP Member
Posts: 369
Joined: Tue Oct 27, 2020 4:09 am
Contact:

Re: Fatal Error

by raiwa » Thu Jun 09, 2022 11:06 am

If you get a zero as response without error message, then it seems the discount code does not get validated for some reason. Please check all options.
Public Phoenix Change Log Cheat Set on Google Sheets
https://docs.google.com/spreadsheets/d/ ... sp=sharing

Need Help?viewtopic.php?f=10&t=27
raiwa
PhoenixCart Developer
PhoenixCart Developer
Posts: 1212
Joined: Sat Dec 21, 2019 8:08 am
Contact: