Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
By PipSqueak
#816257
Hi,

I'm getting the following error in my trigger
Code: Select all
syntax error, unexpected 'if' (T_IF)
When I looked at my code, they looked alright. I can't figure out why it is not parsing it properly. Can you please have a look? I am trying to POST using XML format, I tried both the following and both did not work.
Code: Select all
  CURLOPT_POSTFIELDS => "<?xml version='1.0' encoding='UTF-8'?>
<Customer>
    <Alpha>" . $Alpha . "</Alpha>
    <Name>" . 
	if (isset($BusinessNameAlternative)):
    			$BusinessNameAlternative;
	elseif (isset($BusinessNameDropDown)):
    			$BusinessNameDropDown;
	else : 
	$companyName;
	endif; 
	. "</Name>
and
Code: Select all
  CURLOPT_POSTFIELDS => "<?xml version='1.0' encoding='UTF-8'?>
<Customer>
    <Alpha>" . $Alpha . "</Alpha>
    <Name>" . 
if (isset($BusinessNameAlternative)) 
{
    			$BusinessNameAlternative;
} elseif (isset($BusinessNameDropDown)) {
  			$BusinessNameDropDown;
} else {
	$companyName;
}
	. "</Name>
User avatar
By amosbatto
#816274
If you are concatenating strings in PHP, then you need to use the ? : operator like this:
Code: Select all
  "CURLOPT_POSTFIELDS" => "<?xml version='1.0' encoding='UTF-8'?>
<Customer>
    <Alpha>" . $Alpha . "</Alpha>
    <Name>" . 
	isset($BusinessNameAlternative) ?  $BusinessNameAlternative : 
        ( isset($BusinessNameDropDown) ? $BusinessNameDropDown : $companyName)
	. "</Name>
Also, CURLOPT_POSTFIELDS should probably be in quotations marks, because it is a string.
By PipSqueak
#816277
Thanks Amos, it kinda of worked. But the API responded with "syntax error".

It may be a long shot, but maybe you have an idea what's wrong with it?

I typed only $BusinessNameAlternative and it worked (the string is "Alternative Name"), but when I use the IF/elseif/else (?:) it gives me the "syntax error" error. I made sure it is a string with strtoupper and made sure it's utf8 with utf8_encode. Nothing seems to have worked. There is also no special symbols in the BusinessNameAlternative string to create any hiccups.
Code: Select all
    <Name>" . isset($BusinessNameAlternative) ?  strtoupper(utf8_encode($BusinessNameAlternative)) : 
        (isset($BusinessNameDropDown) ? strtoupper(utf8_encode($BusinessNameDropDown)) : strtoupper(utf8_encode($companyName))) . "</Name>
Error:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<Error><StatusCode>500</StatusCode><StatusPhrase>8901: ALTERNATIVE NAME</StatusPhrase><Message>8901: ALTERNATIVE NAME</Message><Exception>8901</Exception></Error>
Error from the ERP:
Code: Select all
Exception Type: JadeXMLException (8901 : XML parser error)  (Not continuable, resumable)
Extended Text : syntax error
Error Item: Alternative Name
Error Object: <null> (Invalid object reference)
Caused By:
     Receiver: ApiXmlDeserialiser/4215783.47
     Method: <<ApiXmlDeserialiser/4215783.47>> RootSchema::JadeXMLParser::parseString (583)  (ExternalMethod)
Reported By: 
In CardSchema::CnStackDump::exceptionHandler, exObj.errorObject was null, exception=1090, resumable=true
     Receiver: <No reportingMethodDesc, receiver details not available>
     Method: <No reportingMethodDesc, method details not available>

Experience heightened pleasure with Cenforce 100 M[…]

Get an instant solution to move emails to MBOX for[…]

Most Demanding OST to PST Converter

The most demanding OST to PST Converter is TrijaT[…]

Betvisa clone scripts are pre-built software solut[…]