So if your importing an xml file to mysql, but image_14 below doesn't exists in the xml file it fails, but if it does exists it works. I will be doing this with several xml files, some may have all 14 and some may not.
<data>
<Images>
<item0>
<ImageID>1</ImageID>
</item0>
<item1>
<ImageID>2</ImageID>
</item1>
</data>
<?php
$xmlDoc = new DOMDocument();
$xmlDoc->load("file.xml");
$mysql_hostname = ""; // Example : localhost
$mysql_user = "";
$mysql_password = "";
$mysql_database = "";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Oops some thing went wrong");
mysql_select_db($mysql_database, $bd) or die("Oops some thing went wrong");
$xmlObject = $xmlDoc->getElementsByTagName('data');
$itemCount = $xmlObject->length;
for ($i=0; $i < $itemCount; $i++){
$image_1 = $xmlObject->item($i)->getElementsByTagName('ImageID')->item(0)->childNodes->item(0)->nodeValue;
$image_2 = $xmlObject->item($i)->getElementsByTagName('ImageID')->item(1)->childNodes->item(0)->nodeValue;
$image_3 = $xmlObject->item($i)->getElementsByTagName('ImageID')->item(2)->childNodes->item(0)->nodeValue;
$image_4 = $xmlObject->item($i)->getElementsByTagName('ImageID')->item(3)->childNodes->item(0)->nodeValue;
$image_5 = $xmlObject->item($i)->getElementsByTagName('ImageID')->item(4)->childNodes->item(0)->nodeValue;
$image_6 = $xmlObject->item($i)->getElementsByTagName('ImageID')->item(5)->childNodes->item(0)->nodeValue;
$image_7 = $xmlObject->item($i)->getElementsByTagName('ImageID')->item(6)->childNodes->item(0)->nodeValue;
$image_8 = $xmlObject->item($i)->getElementsByTagName('ImageID')->item(7)->childNodes->item(0)->nodeValue;
$image_9 = $xmlObject->item($i)->getElementsByTagName('ImageID')->item(8)->childNodes->item(0)->nodeValue;
$image_10 = $xmlObject->item($i)->getElementsByTagName('ImageID')->item(9)->childNodes->item(0)->nodeValue;
$image_11 = $xmlObject->item($i)->getElementsByTagName('ImageID')->item(10)->childNodes->item(0)->nodeValue;
$image_12 = $xmlObject->item($i)->getElementsByTagName('ImageID')->item(11)->childNodes->item(0)->nodeValue;
$image_13 = $xmlObject->item($i)->getElementsByTagName('ImageID')->item(12)->childNodes->item(0)->nodeValue;
$image_14 = $xmlObject->item($i)->getElementsByTagName('ImageID')->item(13)->childNodes->item(0)->nodeValue;
$sql = "INSERT INTO `$site` (
image_1,
image_2,
image_3,
image_4,
image_5,
image_6,
image_7,
image_8,
image_9,
image_10,
image_11,
image_12,
image_13,
image_14,
image_15,
image_16,
image_17,
image_18,
image_19,
image_20,
image_21,
image_22,
image_23,
image_24,
image_25,
image_26,
image_27,
image_28,
image_29,
image_30
) VALUES ('$image_1', '$image_2', '$image_3', '$image_4', '$image_5', '$image_6', '$image_7', '$image_8', '$image_9', '$image_10', '$image_11', '$image_12', '$image_13', '$image_14', '$image_15', '$image_16', '$image_17', '$image_18', '$image_19', '$image_20', '$image_21', '$image_22', '$image_23', '$image_24', '$image_25', '$image_26', '$image_27', '$image_28', '$image_29', '$image_30')";
mysql_query($sql);
print "Finished";
}
?>
By this way .. it will work fine