Author Topic: Getting MySql Error (v1.2.13)  (Read 6660 times)

Offline rigrax

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Getting MySql Error (v1.2.13)
« on: March 13, 2019, 10:57:03 AM »
WHAT I'M SEEING:

There has been a critical error processing your request
SQL Error:   Error No: 0
SQL: in /home/xxxxx/public_html/xxxx/xxxx/core/database/amysqli.php on line 114
(I have removed folder names for secuity's sake)

MY PURPOSE:
I'm testing the ability to add a simple db query on the   storefront/view/default/template/common/success.tpl    page and to return two lines of results to the page for the user.   This is in preparation for adding code for other backend actions.

WHAT I DID:
I inserted the query in the success.tpl file, based on syntax found in storefront/model/checkout/order.php    (line 152).

QUERY I ADDED IS IN RED:
[LINE 8]   <section class="mb40">
<h4 class="hidden">&nbsp;</h4>
   <p><?php echo $text_message; ?></p>
   <?php $query = $this->db->query("SELECT MAX(order_id) AS order_id FROM `".$this->db->table("orders")."`");
            $result = $this->db->query($sql);
            $row = $result->row;
            echo $row['order_id'];
            echo $row['firstname'];
        ?>

   <a href="<?php echo $continue; ?>" class="btn btn-default mr10" title="<?php echo $continue_button->text ?>">
       <i class="fa fa-arrow-right"></i>
       <?php echo $continue_button->text ?>
   </a>
</section>

What am I missing? The error shown isn't explicit enough to hint at the problem.
Thank you in advance for help.
RIGRAX

Offline Basara

  • Administrator
  • Hero Member
  • *****
  • Posts: 5774
  • Karma: +274/-2
    • View Profile
Re: Getting MySql Error (v1.2.13)
« Reply #1 on: March 14, 2019, 02:00:37 AM »
Hello.

I dont think that .tpl file is right place for SQL query.
SQL should be in the model

Offline rigrax

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: Getting MySql Error (v1.2.13)
« Reply #2 on: March 14, 2019, 10:11:20 AM »
Yes, I know; but this is just testing. Do you have any tip for me?
Thanks.

Offline rigrax

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: Getting MySql Error (v1.2.13)
« Reply #3 on: March 14, 2019, 11:46:55 AM »
I will be happy to add my code in the storefront model      orders.php
So my original question is now altered:  What are the steps I must take, after getting the data I want, to insert the data into a DIFFERENT database on the same server?

Where can I securely add the required login credentials/db connection code for the receiving db?
Thanks!

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2046
  • Karma: +318/-13
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: Getting MySql Error (v1.2.13)
« Reply #4 on: March 15, 2019, 06:04:09 AM »
 $query = $this->db->query("SELECT MAX(order_id) AS order_id FROM `".$this->db->table("orders")."`");
            $result = $this->db->query($sql);

why you do $this->db->query() twice?
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

Offline rigrax

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: Getting MySql Error (v1.2.13)
« Reply #5 on: March 15, 2019, 08:22:05 AM »
I wrote earlier: based on syntax found in storefront/model/checkout/order.php    (line 152), assuming Abantecart's own code would be the right format....
Is the rest of the code I wrote correct?
What are the steps I must take, after getting the data I want, to insert the data into a DIFFERENT database on the same server?
Thanks for the feedback abolado

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2046
  • Karma: +318/-13
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: Getting MySql Error (v1.2.13)
« Reply #6 on: March 15, 2019, 10:36:03 AM »
i mean you write incorrect.
Try this

$sql = "SELECT MAX(order_id) AS order_id FROM `".$this->db->table("orders")."`";
$result = $this->db->query($sql);

$max_order_id = $result->row['order_id'];
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

Offline rigrax

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: Getting MySql Error (v1.2.13)
« Reply #7 on: March 15, 2019, 10:49:45 AM »
Thanks; I see what you  meant now....  I'll try this when I get back to the office.

Offline rigrax

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: Getting MySql Error (v1.2.13)
« Reply #8 on: March 16, 2019, 08:23:10 AM »
After correcting the amysqli.php error remains, but the order IS going through (I am receiving the confirmation emails in admin and to user).
This happens when placing the code on the tpl page, and as noted, this isn't where it should go.....

But I think it's redundant to add this sql to the order.php model, since code is already there to return some of the data I want.

It seems logical to me that I should be able to insert a hook on the success.tpl page to bring the data there.
If this is correct, what should the syntax for that be?

Thanks for the aid!

 

Powered by SMFPacks Social Login Mod