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>aaa@mydomain.net</email>
        <phone>+49 341 789 123</phone>
        <fax>+49 341 789 123</fax>
    </address>
</shipping>
    </order>';
//some code

?>

2 Answers2

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.

Community
  • 1
  • 1
camelCase
  • 5,460
  • 3
  • 34
  • 37
0

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