Post by DawidXT » Tue Mar 16, 2021 6:47 pm

OpenCart: version 3.0.3.1
Theme: https://www.webibazaar.com/opencart-the ... sive-theme

I see this seems to be common issue, at least what the error says in header... but the rest of my problem I guess in the individual issue, that's why I created new topic about this instead of writing in one of the existing one. The problem is same on few servers I tested it. No matter what payment option I use, or shipping.

While I go to check my client's order detail as an admin I every time see this error, each time I refresh the page, on each order type.
(please see the attachments) or by going to this link: https://imgur.com/a/ydOG1ji

I tried to hand write part of this error message (I cant copy this from the alert window ;( )

Code: Select all

SyntaxError: Unexpected token < in JSON at position 0
OK

<b>Notice</b>: Undefined index: api_token in <b>/home/name/domains/name/public_html/catalog/controller/startup/session.php</b> on line <b>8</b><b>Notice</b>: Undefined index: username in <b>/home/name/domains/name/public_html/catalog/controller/api/login.php</b> on line
<b>11</b><br />

<b>Fatal error</b>: Uncaught Exception: Error: Something is wrong in your syntax obok ’key’ = „ AND status = ’1’’ in line 1&lt;br / &gt;Error No: 1064&lt;br /&gt;SELECT * FROM ’oc_api’ WHERE ’username’ = ’’ ’key’ = ’’ AND status = ’1’ in home/name/domains/name/public_html/system/library/db/mysqli.php:40

Stack trace: 
Does anyone have a clue whats going on?
Sorry for my English

Attachments

error-itself.png

error-itself.png (116.35 KiB) Viewed 1666 times

page-where-the-error-occurs.png

page-where-the-error-occurs.png (210.41 KiB) Viewed 1666 times


Newbie

Posts

Joined
Wed Apr 12, 2017 11:29 pm

Post by paulfeakins » Tue Mar 16, 2021 7:04 pm

Looks like an OCMOD is causing it as the error mentions the modifications dir.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Guru Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by DawidXT » Tue Mar 16, 2021 8:47 pm

in extensions/modification I have only three items there:
- Webi QuickView
- Smartsupp Live Chat
- Inpost (a shipping method)
or perhaps You mean something else by writing ocmod. Is this possible to tell more which one drops this error?

Newbie

Posts

Joined
Wed Apr 12, 2017 11:29 pm

Post by ADD Creative » Tue Mar 16, 2021 10:35 pm

DawidXT wrote:
Tue Mar 16, 2021 8:47 pm
in extensions/modification I have only three items there:
- Webi QuickView
- Smartsupp Live Chat
- Inpost (a shipping method)
or perhaps You mean something else by writing ocmod. Is this possible to tell more which one drops this error?
Look in your OpenCart and PHP error logs for more details on the errors.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by DawidXT » Wed Mar 17, 2021 12:01 am

OpenCart's log shows me just this two lines after I get the error:

Code: Select all

2021-03-16 15:53:53 - PHP Notice:  Undefined index: api_token in /home/name/domains/name/public_html/catalog/controller/startup/session.php on line 8
2021-03-16 15:53:53 - PHP Notice:  Undefined index: username in /home/name/domains/name/public_html/catalog/controller/api/login.php on line 11

Newbie

Posts

Joined
Wed Apr 12, 2017 11:29 pm

Post by sw!tch » Wed Mar 17, 2021 1:32 am

Do you have an API user set?

Admin->System->Users-> API ?

Full Stack Web Developer :: Send a PM for Custom Work.
Backup and learn how to recover before you make any changes!


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm

Post by DawidXT » Wed Mar 17, 2021 2:14 am

yeah, I do have - two. I did not create any of them... what I should do with them? (see the attachment)

Attachments

Zrzut ekranu 2021-03-16 o 19.13.55.png

Zrzut ekranu 2021-03-16 o 19.13.55.png (34.74 KiB) Viewed 1581 times


Newbie

Posts

Joined
Wed Apr 12, 2017 11:29 pm

Post by sw!tch » Wed Mar 17, 2021 4:32 am


Full Stack Web Developer :: Send a PM for Custom Work.
Backup and learn how to recover before you make any changes!


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm

Post by DawidXT » Wed Mar 17, 2021 5:05 am

hmm, now only this line left:

Code: Select all

2021-03-16 21:03:54 - PHP Notice:  Undefined index: username in /home/name/domains/name/public_html/catalog/controller/api/login.php on line 11
hopefully, we are heading in the right direction

Newbie

Posts

Joined
Wed Apr 12, 2017 11:29 pm

Post by sw!tch » Wed Mar 17, 2021 5:24 am

DawidXT wrote:
Wed Mar 17, 2021 5:05 am
hmm, now only this line left:

Code: Select all

2021-03-16 21:03:54 - PHP Notice:  Undefined index: username in /home/name/domains/name/public_html/catalog/controller/api/login.php on line 11
hopefully, we are heading in the right direction
What does /public_html/catalog/controller/api/login.php on line 11 look like?

Also why do you have two API users called default?

Full Stack Web Developer :: Send a PM for Custom Work.
Backup and learn how to recover before you make any changes!


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm

Post by DawidXT » Wed Mar 17, 2021 7:26 pm

@sw!tch thank You for Your support.
/public_html/catalog/controller/api/login.php on line 11 says:

Code: Select all

$api_info = $this->model_account_api->login($this->request->post['username'], $this->request->post['key']);
And I don't know anything about the API users, why there is two of them, or any of them. I'm not sure what it does, I guess it created itself, or perhaps it was there preinstalled? Can I just delete them? Lately, I changed the name of the default user group, from "default" to "standard". But problems I was having was showing before this change.

Newbie

Posts

Joined
Wed Apr 12, 2017 11:29 pm

Post by DawidXT » Thu Apr 01, 2021 7:56 pm

guys, anyone have some suggestion, idea how to fix this?

Newbie

Posts

Joined
Wed Apr 12, 2017 11:29 pm

Post by ADD Creative » Fri Apr 02, 2021 12:16 am

Check your catalog/controller/api/login.php file as line 11 should be: https://github.com/opencart/opencart/bl ... in.php#L11

Also switch off display errors and use you log files, as when errors are displayed it causes the JSON error.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by DawidXT » Thu Apr 15, 2021 7:58 pm

ADD Creative,
sorry for so long replay. I thought no one will replay me, so I did not check this topic.

I changed my line 11, but not only the line, but full if function.

Code: Select all

<?php
class ControllerApiLogin extends Controller {
	public function index() {
		$this->load->language('api/login');

		$json = array();

		$this->load->model('account/api');

		// Login with API Key
		if(isset($this->request->post['username'])) {
			$api_info = $this->model_account_api->login($this->request->post['username'], $this->request->post['key']);
		} else {
			$api_info = $this->model_account_api->login('Default', $this->request->post['key']);
		}

		if ($api_info) {
			// Check if IP is allowed
			$ip_data = array();
	
			$results = $this->model_account_api->getApiIps($api_info['api_id']);
	
			foreach ($results as $result) {
				$ip_data[] = trim($result['ip']);
			}
	
			if (!in_array($this->request->server['REMOTE_ADDR'], $ip_data)) {
				$json['error']['ip'] = sprintf($this->language->get('error_ip'), $this->request->server['REMOTE_ADDR']);
			}				
				
			if (!$json) {
				$json['success'] = $this->language->get('text_success');
				
				$session = new Session($config->get('session_engine'), $registry);
				$session->start();
				
				$this->model_account_api->addApiSession($api_info['api_id'], $session->getId(), $this->request->server['REMOTE_ADDR']);
				
				$session->data['api_id'] = $api_info['api_id'];
				
				// Create Token
				$json['api_token'] = $session->getId();
			} else {
				$json['error']['key'] = $this->language->get('error_key');
			}
		}
		
		$this->response->addHeader('Content-Type: application/json');
		$this->response->setOutput(json_encode($json));
	}
}

I switched off display errors, but same problem happens, but this time it shows me error in catalog/controller/startup/session.php on line 8.
This file looks like this:

Code: Select all

<?php
class ControllerStartupSession extends Controller {
	public function index() {
		if (isset($this->request->get['route']) && substr($this->request->get['route'], 0, 4) == 'api/') {
			$this->db->query("DELETE FROM `" . DB_PREFIX . "api_session` WHERE TIMESTAMPADD(HOUR, 1, date_modified) < NOW()");
					
			// Make sure the IP is allowed
			$api_query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "api` `a` LEFT JOIN `" . DB_PREFIX . "api_session` `as` ON (a.api_id = as.api_id) LEFT JOIN " . DB_PREFIX . "api_ip `ai` ON (a.api_id = ai.api_id) WHERE a.status = '1' AND `as`.`session_id` = '" . $this->db->escape($this->request->get['api_token']) . "' AND ai.ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "'");
		 
			if ($api_query->num_rows) {
				$this->session->start($this->request->get['api_token']);
				
				// keep the session alive
				$this->db->query("UPDATE `" . DB_PREFIX . "api_session` SET `date_modified` = NOW() WHERE `api_session_id` = '" . (int)$api_query->row['api_session_id'] . "'");
			}
		} else {
			if (isset($_COOKIE[$this->config->get('session_name')])) {
				$session_id = $_COOKIE[$this->config->get('session_name')];
			} else {
				$session_id = '';
			}
			
			$this->session->start($session_id);
			
			setcookie($this->config->get('session_name'), $this->session->getId(), ini_get('session.cookie_lifetime'), ini_get('session.cookie_path'), ini_get('session.cookie_domain'));	
		}
	}
}
the line 8 is this:

Code: Select all

$api_query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "api` `a` LEFT JOIN `" . DB_PREFIX . "api_session` `as` ON (a.api_id = as.api_id) LEFT JOIN " . DB_PREFIX . "api_ip `ai` ON (a.api_id = ai.api_id) WHERE a.status = '1' AND `as`.`session_id` = '" . $this->db->escape($this->request->get['api_token']) . "' AND ai.ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "'");
I guess I have to change it in the same way as I changed the login.php...
Any suggestion what to do now?

Thank You

Newbie

Posts

Joined
Wed Apr 12, 2017 11:29 pm

Post by straightlight » Thu Apr 15, 2021 8:04 pm

Unbelievable. Since the first post:
<b>Fatal error</b>: Uncaught Exception: Error: Something is wrong in your syntax obok ’key’ = „ AND status = ’1’’ in line 1&lt;br / &gt;Error No: 1064&lt;br /&gt;SELECT * FROM ’oc_api’ WHERE ’username’ = ’’ ’key’ = ’’ AND status = ’1’ in home/name/domains/name/public_html/system/library/db/mysqli.php:40
Caused by an installed extension.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by DawidXT » Thu Apr 15, 2021 9:09 pm

In logs i have only this errors:

Code: Select all

2021-04-15 11:34:22 - PHP Notice:  Undefined index: api_token in /Users/username/www/name/catalog/controller/startup/session.php on line 8
2021-04-15 11:34:22 - PHP Notice:  Undefined index: username in /Users/username/www/name/catalog/controller/api/login.php on line 11
2021-04-15 11:38:00 - PHP Notice:  Undefined index: api_token in /Users/username/www/name/catalog/controller/startup/session.php on line 8
2021-04-15 11:39:24 - PHP Notice:  Undefined index: api_token in /Users/username/www/name/catalog/controller/startup/session.php on line 8
2021-04-15 11:40:49 - PHP Notice:  Undefined index: api_token in /Users/username/www/name/catalog/controller/startup/session.php on line 8
I tried to replace also this: viewtopic.php?f=198&t=202726&p=716825&h ... en#p716825
But now I am getting popup internal server error message while going to the order detail page.

It' first time I am trying to use OpenCart, and it's really hard for beginners...

Newbie

Posts

Joined
Wed Apr 12, 2017 11:29 pm

Post by straightlight » Thu Apr 15, 2021 9:12 pm

DawidXT wrote:
Thu Apr 15, 2021 9:09 pm
In logs i have only this errors:

Code: Select all

2021-04-15 11:34:22 - PHP Notice:  Undefined index: api_token in /Users/username/www/name/catalog/controller/startup/session.php on line 8
2021-04-15 11:34:22 - PHP Notice:  Undefined index: username in /Users/username/www/name/catalog/controller/api/login.php on line 11
2021-04-15 11:38:00 - PHP Notice:  Undefined index: api_token in /Users/username/www/name/catalog/controller/startup/session.php on line 8
2021-04-15 11:39:24 - PHP Notice:  Undefined index: api_token in /Users/username/www/name/catalog/controller/startup/session.php on line 8
2021-04-15 11:40:49 - PHP Notice:  Undefined index: api_token in /Users/username/www/name/catalog/controller/startup/session.php on line 8
I tried to replace also this: viewtopic.php?f=198&t=202726&p=716825&h ... en#p716825
But now I am getting popup internal server error message while going to the order detail page.

It' first time I am trying to use OpenCart, and it's really hard for beginners...
In this case, there's no need to install an older version of OC. I would, then, suggest to use the latest version of Opencart which contains most of the bug-fixes that's been reported in the past.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by DawidXT » Thu Apr 15, 2021 9:27 pm

I was trying to install the theme on the newest opencart, but the theme i am using comes with the complete starterpack , and this is the version i am using now. I was having hard time trying to install this theme on the latest version of the OpenCart...
How to tell which plugin is causing this error?

Newbie

Posts

Joined
Wed Apr 12, 2017 11:29 pm

Post by straightlight » Thu Apr 15, 2021 9:48 pm

DawidXT wrote:
Thu Apr 15, 2021 9:27 pm
I was trying to install the theme on the newest opencart, but the theme i am using comes with the complete starterpack , and this is the version i am using now. I was having hard time trying to install this theme on the latest version of the OpenCart...
How to tell which plugin is causing this error?
Then, my analysis above was correct. In this case, you need to get in touch with the extension theme developer where you downloaded this extension originally.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by ADD Creative » Thu Apr 15, 2021 11:04 pm

DawidXT wrote:
Thu Apr 15, 2021 7:58 pm
ADD Creative,
sorry for so long replay. I thought no one will replay me, so I did not check this topic.

I changed my line 11, but not only the line, but full if function.

I switched off display errors, but same problem happens, but this time it shows me error in catalog/controller/startup/session.php on line 8.
This file looks like this:

Code: Select all

<?php
class ControllerStartupSession extends Controller {
	public function index() {
		if (isset($this->request->get['route']) && substr($this->request->get['route'], 0, 4) == 'api/') {
			$this->db->query("DELETE FROM `" . DB_PREFIX . "api_session` WHERE TIMESTAMPADD(HOUR, 1, date_modified) < NOW()");
					
			// Make sure the IP is allowed
			$api_query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "api` `a` LEFT JOIN `" . DB_PREFIX . "api_session` `as` ON (a.api_id = as.api_id) LEFT JOIN " . DB_PREFIX . "api_ip `ai` ON (a.api_id = ai.api_id) WHERE a.status = '1' AND `as`.`session_id` = '" . $this->db->escape($this->request->get['api_token']) . "' AND ai.ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "'");
		 
			if ($api_query->num_rows) {
				$this->session->start($this->request->get['api_token']);
				
				// keep the session alive
				$this->db->query("UPDATE `" . DB_PREFIX . "api_session` SET `date_modified` = NOW() WHERE `api_session_id` = '" . (int)$api_query->row['api_session_id'] . "'");
			}
		} else {
			if (isset($_COOKIE[$this->config->get('session_name')])) {
				$session_id = $_COOKIE[$this->config->get('session_name')];
			} else {
				$session_id = '';
			}
			
			$this->session->start($session_id);
			
			setcookie($this->config->get('session_name'), $this->session->getId(), ini_get('session.cookie_lifetime'), ini_get('session.cookie_path'), ini_get('session.cookie_domain'));	
		}
	}
}
the line 8 is this:

Code: Select all

$api_query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "api` `a` LEFT JOIN `" . DB_PREFIX . "api_session` `as` ON (a.api_id = as.api_id) LEFT JOIN " . DB_PREFIX . "api_ip `ai` ON (a.api_id = ai.api_id) WHERE a.status = '1' AND `as`.`session_id` = '" . $this->db->escape($this->request->get['api_token']) . "' AND ai.ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "'");
I guess I have to change it in the same way as I changed the login.php...
Any suggestion what to do now?

Thank You
Your catalog/controller/startup/session.php also doesn't match the file in 3.0.3.1.
https://github.com/opencart/opencart/bl ... ession.php

You could have other files that aren't from version 3.0.3.1. Maybe you have the wrong version of these and other files due to a failed upgrade or a theme/extension has overwritten some files with older versions.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom
Who is online

Users browsing this forum: Bing [Bot], Semrush [Bot] and 266 guests