5

Hello and thank you for your help,

I am using PHP to write an XML request, the problem I am having is when I use the variable in the value field, it returns an error. However when I write in the value manually it works perfectly. Under field name='Serial_Number' you will see the $MREPSerial is the variable, let's assume that in the PHP we have $MREPSerial = 'A-000-1042'; The below XML would give an error. However if i were to replace $MREPSerial with just the value in the XML it would be successful. Any help would be greatly appreciated. Thank you!

$MREPSerial  = htmlspecialchars(strtoupper($_POST['NSMREP']));
echo "Hi".$MREPSerial;
<ZohoCreator>
            <applicationlist>
                <application name='ajout-de-materiel'>
                    <formlist>
                        <form name='MREP'>
                            <update>
                                <criteria>
                                    <field name='Serial_Number' compOperator='Equals' value={$MREPSerial}></field>
                                    <reloperator>AND</reloperator>
                                    <field name='MREP_Type' compOperator='Equals' value='0'></field>                            
                                </criteria>
                                <newvalues>
                                    <field name='Is_being_Used' value='TRUE'></field>
                                </newvalues>
                            </update>    
                        </form>
                    </formlist>
                </application>
            </applicationlist>
        </ZohoCreator>";

... the return response on echo (including the XML i echoed)

A-000-1012HI! <?xml version="1.0" encoding="UTF-8" ?>
<response><errorlist><error><code>2830</code><message><![CDATA[Open quote is expected for attribute "value" associated with an  element type  "field".]]></message></error></errorlist></response>

the return response on echo if i change it to '".$MREPSerial." is:

A-000-1012HI! <?xml version="1.0" encoding="UTF-8" ?>
<response><result><form name="MREP"><update><criteria><field name="Serial_Number" compOperator="Equals" value=""></field><reloperator>AND</reloperator><field name="MREP_Type" compOperator="Equals" value="0"></field></criteria><newvalues><field name="Is_being_Used"><value><![CDATA[TRUE]]></value></field></newvalues> <status>Failure, No Records Found With Specified Criteria</status></update></form></result></response>
J Noel
  • 103
  • 1
  • 1
  • 8
  • how are you jumping in and out of PHP? `...compOperator='Equals' value=''>...` – Dave Sep 13 '12 at 18:15
  • Sorry this is all in PHP I just didn't add the entire PHP page, the XML is a variable $param = "XMLString= .... – J Noel Sep 13 '12 at 18:18
  • can you do the following for me; `echo '[['.$MREPSerial.']]';` and show the output again... – Dave Sep 13 '12 at 18:31
  • on echo this is what is returned [[A-000-1012]] (the 1012 is because I changed the number, but should work) – J Noel Sep 13 '12 at 18:34
  • 1
    no clue... doesn't make sense. Perhaps post a wider section of code before/after including where you assign and test output the $MREPSerial... perhaps it is something else. – Dave Sep 13 '12 at 19:50
  • Thanks Dave, you were right it was something somewhat stupid. Since my XML is called in a function and my variable is called outside the function, I was not getting the value. I had to make it global. – J Noel Sep 13 '12 at 20:35

2 Answers2

3

You need quotes around the value attribute's actual value, like this:

<field name='Serial_Number' compOperator='Equals' value='{$MREPSerial}'></field>
Mike Brant
  • 70,514
  • 10
  • 99
  • 103
  • Thank you for your response, unfortunatley I tried that and I received the XML message instead of FALSE value does not exist, and that is because the XML shows the value as blank (shown below) – J Noel Sep 13 '12 at 18:16
  • are you sure the variable is populated? – Dave Sep 13 '12 at 18:20
  • If the value is blank, then the problem is in outputting your variable. Do you need an `echo` or `print` in there. I wasn't sure how you were using this template, so I didn't comment on that. If empty string are permissible, then perhaps you need to write `'null'` or something else here as placeholder for empty string. – Mike Brant Sep 13 '12 at 18:21
  • The value is populate, I have echoed the value and it shows, I will edit the information to show how I did this. – J Noel Sep 13 '12 at 18:22
0

just saw your "; close tag...

try this for that line

 <field name='Serial_Number' compOperator='Equals' value='".$MREPSerial."'></field> 
Dave
  • 991
  • 1
  • 7
  • 15
  • Thanks for your response, also gives the same error
    AND<![CDATA[TRUE]]> Failure, No Records Found With Specified Criteria
    – J Noel Sep 13 '12 at 18:21