0

I'm retrieving an XML code from the database and storing it as a variable in php. However when I try to use this variable inside an XML code, it gives me an error. Here is my code:

<?php

          $conn = mysqli_connect('localhost', 'root', '', 'thisdatabase');
          $result = mysqli_query($conn, 'SELECT * FROM createdproduct');
          while ($row = mysqli_fetch_assoc($result))
          {
            //$selected = (isset($_POST['list']) && $_POST['list'] ==  $row['id']) ? 'selected' : '';
              //echo htmlentities($row["productURL"]);
              $test = htmlspecialchars($row["productURL"]);
          }


          //echo htmlentities($test);
?>

and this is my XML wrapped in php:

<?php
//some code

    $xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <order xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://api.mydomain.net">
        <orderItems>
            '.$test.'
        </orderItems>
        <payment>
            <type>typ</type>
        </payment>
<shipping>
    <shippingType id="00"/>
     <address type="private">
        <person> <
            <salution id="1"/>
            <firstName>person</firstName>
            <lastName>person</lastName>
        </person>
        <street>street</street>
        <houseNumber>00</houseNumber>
        <city>city</city>
        <country code="US">USA</country>
        <state code="mm">California</state>
        <zipCode>111</zipCode>
        <email>[email protected]</email>
        <phone>+49 341 789 123</phone>
        <fax>+49 341 789 123</fax>
    </address>
</shipping>
    </order>';
//some code

?>
6
  • 3
    Including your error may help others identify the issue. Commented Oct 7, 2015 at 15:09
  • @InbetweenWeekends this the the error I get fro the api: {"message":"Some Error\n","curlRequest":"curl -i -L --compressed -H \"Accept-Encoding: gzip,deflate\" Commented Oct 7, 2015 at 15:15
  • If you do something like $test = 'product name'; does it still produce the error? Commented Oct 7, 2015 at 15:55
  • @camelCase I have to use htmlentities, because I'm retrieving an XML code that uses html tags. Commented Oct 7, 2015 at 16:31
  • 1
    Be sure $test does not include XML reserved characters that would require encoding: >, <, &, %. Commented Oct 7, 2015 at 17:03

2 Answers 2

0

Your error code is rather generic but I suspect the issue is in the data you're pulling from the database and using in the $test variable.

As discussed above, you might try confirming this by using a simple word in place of the actual data, like: $test = 'something';. The reason I believe this to be the problem is because htmlentities() is intended for use in HTML, not XML.

You might consider trying htmlspecialchars() instead.

EDIT: I knew I had read this on SO somewhere, check this post out for further detailed information.

Sign up to request clarification or add additional context in comments.

Comments

0

I was able to get the result I wanted using html_entity_decode. Thank you

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.