[Skip to main content](#vessel-content)

#   Mass Action Error - Action PHP code is wrong: syntax error, unexpected token "

##

- **[marius84bv](/forum/user/78996-marius84bv "View marius84bv's Profile")**
- [![marius84bv's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/78996-marius84bv "View marius84bv's Profile") Topic Author
- [ Offline](/forum/user/78996-marius84bv)

Less More

- Posts: 1
- Thank you received: 0
-
-

2 years 11 months ago -  2 years 11 months ago [\#357747](#357747) by [marius84bv](/forum/user/78996-marius84bv "View marius84bv's Profile")  *[Mass Action Error - Action PHP code is wrong: syntax error, unexpected token "](/forum/25-install-update/907493-mass-action-error-action-php-code-is-wrong-syntax-error-unexpected-token#357747 "-- HikaShop version -- : 5.0.2 -- Joomla version -- : 5.0.1 -- PHP version -- : 8.1.26 -- Browser(s) name and version -- : Google Chrome -- Error-message(debug-mod must be tuned on) -- : Action PHP code is wrong: syntax error, unexpected token &quot;  Hello. I am trying to execute a PHP code in Mass Action that will transfer data to an API. I get this error - Action PHP code is wrong: syntax error, unexpected token &quot;  At this moment I don't know what I should try to be able to send the code to the invoicing system API. Please help me understand where I am wrong or what I should do. Thank you")* was created by *[marius84bv](/forum/user/78996-marius84bv "View marius84bv's Profile")*

-- HikaShop version -- : 5.0.2
-- Joomla version -- : 5.0.1
-- PHP version -- : 8.1.26
-- Browser(s) name and version -- : Google Chrome
-- Error-message(debug-mod must be tuned on) -- : Action PHP code is wrong: syntax error, unexpected token "

Hello.
I am trying to execute a PHP code in Mass Action that will transfer data to an API.
I get this error - Action PHP code is wrong: syntax error, unexpected token "
Code:

&lt;?php // Presupunând că ai ID-ul adresei de facturare $billingAddressId = '{order_billing_address_id}'; // Conexiunea la baza de date Joomla $db = JFactory::getDbo(); // Construim prima interogare pentru a obține detalii despre adresă $query = $db-&gt;getQuery(true); $query-&gt;select($db-&gt;quoteName(array('address_company', 'address_vat', 'address_firstname', 'address_lastname', 'address_street', 'address_state', 'address_country'))); $query-&gt;from($db-&gt;quoteName('db_name_hikashop_address')); $query-&gt;where($db-&gt;quoteName('address_id') . ' = ' . $db-&gt;quote($billingAddressId)); // Executăm prima interogare $db-&gt;setQuery($query); $addressResult = $db-&gt;loadAssoc(); if ($addressResult) { // Extragem codul de stat și codul țării $stateCode = substr($addressResult['address_state'], strrpos($addressResult['address_state'], '_') + 1); $countryCode = substr($addressResult['address_country'], strrpos($addressResult['address_country'], '_') + 1); // Interogare pentru numele zonei $query = $db-&gt;getQuery(true); $query-&gt;select($db-&gt;quoteName('zone_name')); $query-&gt;from($db-&gt;quoteName('db_name_hikashop_zone')); $query-&gt;where($db-&gt;quoteName('zone_id') . ' = ' . $db-&gt;quote($stateCode)); $db-&gt;setQuery($query); $zoneName = $db-&gt;loadResult(); // Interogare pentru numele țării $query = $db-&gt;getQuery(true); $query-&gt;select($db-&gt;quoteName('zone_name')); $query-&gt;from($db-&gt;quoteName('db_name_hikashop_zone')); $query-&gt;where($db-&gt;quoteName('zone_id') . ' = ' . $db-&gt;quote($countryCode)); $db-&gt;setQuery($query); $countryName = $db-&gt;loadResult(); // Pregătim datele pentru API-ul SmartBill $smartBillData = [ "data" =&gt; date("Y-m-d"), "client" =&gt; [ "nume" =&gt; $addressResult['address_firstname'] . " " . $addressResult['address_lastname'], "cif" =&gt; "48956989", "regCom" =&gt; "", "adresa" =&gt; $addressResult['address_street'] . ", " . ($zoneName ? $zoneName : 'Unknown') . ", " . ($countryName ? $countryName : 'Unknown'), // Alte detalii despre client ], // Produsele sau serviciile facturate // ... ]; // URL-ul API-ului SmartBill $url = 'https://api.invoice-web-app-ro'; // Inițializăm sesiunea cURL $ch = curl_init($url); // Setăm opțiunile cURL necesare curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($smartBillData)); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'Authorization: Basic ' . base64_encode("mail:tokenkey") ]); // Executăm cererea cURL $response = curl_exec($ch); $curlError = curl_error($ch); // Închidem sesiunea cURL curl_close($ch); // Afișăm răspunsul sau eroarea în consola JavaScript echo "&lt;script type='text/javascript'&gt;"; if ($curlError) { echo "console.error('Eroare cURL: " . json_encode($curlError) . "');"; } else { echo "console.log('Răspuns SmartBill: " . json_encode($response) . "');"; } echo "&lt;/script&gt;"; } else { echo "&lt;script&gt;console.log('No address or zone result found');&lt;/script&gt;"; } ?&gt; I tested the version of the php code that brings certain information to the console to do tests and it works perfectly. // Presupunând că ai ID-ul adresei de facturare $billingAddressId = '{order_billing_address_id}'; // Înlocuiește cu eticheta corectă // Conexiunea la baza de date Joomla $db = JFactory::getDbo(); // Construim prima interogare pentru a obține detalii despre adresă $query = $db-&gt;getQuery(true); $query-&gt;select($db-&gt;quoteName(array('address_company', 'address_vat', 'address_firstname', 'address_lastname', 'address_street', 'address_state', 'address_country'))); $query-&gt;from($db-&gt;quoteName('db_name_hikashop_address')); $query-&gt;where($db-&gt;quoteName('address_id') . ' = ' . $db-&gt;quote($billingAddressId)); // Executăm prima interogare $db-&gt;setQuery($query); $addressResult = $db-&gt;loadAssoc(); if ($addressResult) { // Extragem codul de stat și codul țării $stateCode = substr($addressResult['address_state'], strrpos($addressResult['address_state'], '_') + 1); $countryCode = substr($addressResult['address_country'], strrpos($addressResult['address_country'], '_') + 1); // Interogare pentru numele zonei $query = $db-&gt;getQuery(true); $query-&gt;select($db-&gt;quoteName('zone_name')); $query-&gt;from($db-&gt;quoteName('db_name_hikashop_zone')); $query-&gt;where($db-&gt;quoteName('zone_id') . ' = ' . $db-&gt;quote($stateCode)); $db-&gt;setQuery($query); $zoneName = $db-&gt;loadResult(); // Interogare pentru numele țării $query = $db-&gt;getQuery(true); $query-&gt;select($db-&gt;quoteName('zone_name')); $query-&gt;from($db-&gt;quoteName('db_name_hikashop_zone')); $query-&gt;where($db-&gt;quoteName('zone_id') . ' = ' . $db-&gt;quote($countryCode)); $db-&gt;setQuery($query); $countryName = $db-&gt;loadResult(); // Pregătim informațiile pentru afișare $company = addslashes($addressResult['address_company']); $vat = addslashes($addressResult['address_vat']); $firstname = addslashes($addressResult['address_firstname']); $lastname = addslashes($addressResult['address_lastname']); $street = addslashes($addressResult['address_street']); $state = $zoneName ? addslashes($zoneName) : 'Unknown'; $country = $countryName ? addslashes($countryName) : 'Unknown'; // Afișăm informațiile în consola JavaScript echo "&lt;script&gt;console.log('Address Company: $company, VAT: $vat, First Name: $firstname, Last Name: $lastname, Street: $street, State: $state, Country: $country');&lt;/script&gt;"; } else { echo "&lt;script&gt;console.log('No address result found');&lt;/script&gt;"; } I tested php code with cURL for simplified test but I get the same error &lt;?php $url = "https://bcc-heritage.com/component/hikashop/product/1523-albania-p-41s2-1976-3-leke"; // Inițializarea sesiunii cURL $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Execută cererea cURL $response = curl_exec($curl); curl_close($curl); // Verifică dacă cererea a reușit if ($response) { // Caută titlul în răspunsul HTML if (preg_match('/&lt;title&gt;(.*?)&lt;\/title&gt;/', $response, $matches)) { $title = $matches[1]; echo "Titlul paginii este: " . $title; } else { echo "Nu s-a putut găsi titlul în HTML."; } } else { echo "Cererea cURL a eșuat."; } ?&gt;

At this moment I don't know what I should try to be able to send the code to the invoicing system API.
Please help me understand where I am wrong or what I should do.
Thank you

**\[Moderator:\]**Please do not post long code like this, add a file attachment instead.**\[/Moderator\]**

Last edit: 2 years 11 months ago by [Philip](/forum/user/34318-philip "View Philip's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI1LWluc3RhbGwtdXBkYXRlLzkwNzQ5My1tYXNzLWFjdGlvbi1lcnJvci1hY3Rpb24tcGhwLWNvZGUtaXMtd3Jvbmctc3ludGF4LWVycm9yLXVuZXhwZWN0ZWQtdG9rZW4/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86593
- Thank you received: 14334
-
-

2 years 11 months ago [\#357754](#357754) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Mass Action Error - Action PHP code is wrong: syntax error, unexpected token "](/forum/25-install-update/907493-mass-action-error-action-php-code-is-wrong-syntax-error-unexpected-token#357754 "-- HikaShop version -- : 5.0.2 -- Joomla version -- : 5.0.1 -- PHP version -- : 8.1.26 -- Browser(s) name and version -- : Google Chrome -- Error-message(debug-mod must be tuned on) -- : Action PHP code is wrong: syntax error, unexpected token &quot;  Hello. I am trying to execute a PHP code in Mass Action that will transfer data to an API. I get this error - Action PHP code is wrong: syntax error, unexpected token &quot;  At this moment I don't know what I should try to be able to send the code to the invoicing system API. Please help me understand where I am wrong or what I should do. Thank you")*

Hi,

First, you want to activate the "debug" setting of the Joomla configuration in order to get the full error message.
Now, the error message will point at the line number and file where the problem is.
However, it's it's code that's been "eval" ( [ www.php.net/manual/en/function.eval.php](https://www.php.net/manual/en/function.eval.php) ) by the mass action system, the error message should point at a file of the mass action system and not to where the problem is in your code.
So move your code to a PHP file and in your mass action, just keep the first line Code:

$billingAddressId = '{order_billing_address_id}';

so that it can replace the tag, and then add an include of your PHP file.
That way, the error message will point at your file with the line number in that file so you'll be able to easily pin point the problem in your code.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI1LWluc3RhbGwtdXBkYXRlLzkwNzQ5My1tYXNzLWFjdGlvbi1lcnJvci1hY3Rpb24tcGhwLWNvZGUtaXMtd3Jvbmctc3ludGF4LWVycm9yLXVuZXhwZWN0ZWQtdG9rZW4/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.058 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
