0

the values are not being inserted and also no error is being displayed. Any idea as to what is happening with my insert?

<?php
$string = <<<XML
<?xml version='1.0'?> 
<setnames>
<country>
<countryCode>AD</countryCode>
<countryName>Andorra</countryName>
</country>
<country>
<countryCode>AE</countryCode>
<countryName>United Arab Emirates</countryName>
<isoNumeric>784</isoNumeric>
</country>
<country>
<countryCode>AF</countryCode>
<countryName>Afghanistan</countryName>
<isoNumeric>784</isoNumeric>
</country>
</setnames>
XML;

$xml = simplexml_load_string($string);

foreach ($xml as $country) 
{

mysqli INSERT INTO setnames 
VALUES ($country->countryCode, $country->countryName, $country->isoNumeric);

    echo $country->countryCode . "<br />";
    echo $country->countryName . "<br />";
    echo $country->isoNumeric . "<br />"
}
1
  • What shows var_dump($xml)? Commented Oct 4, 2013 at 20:20

1 Answer 1

1

$xml variable is an object, nor an array. So, you should do your foreach like this:

foreach ($xml->country as $country) 
{

mysqli INSERT INTO setnames 
VALUES ($country->countryCode, $country->countryName, $country->isoNumeric);

    echo $country->countryCode . "<br />";
    echo $country->countryName . "<br />";
    echo $country->isoNumeric . "<br />"
}
Sign up to request clarification or add additional context in comments.

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.