Hello
I am trying to parse XML using PHP DOM and then insert this data in MySQL tables, i am using the following code for this:
<?php
$xmlDoc = new DOMDocument();
$xmlDoc->load("testrtap11.xml");
mysql_select_db("zeeshan_database1", $con);
$x=$xmlDoc->getElementsByTagName('RECORD');
$z=$xmlDoc->getElementsByTagName('TITLE');
$w=$xmlDoc->getElementsByTagName('PRIMARY_AUTHOR');
$y=$xmlDoc->getElementsByTagName('JOURNAL_CONFERENCE');
for($i=0; $i<=$x->length-1; $i++)
{
$sql="INSERT INTO Persons (FirstName, LastName, Age) VALUES('$z->item($i)->nodeValue','$w->item($i)->nodeValue','$y->item($i)->nodeValue')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
}
mysql_close($con)
?>
The data being entered is not correct. i even tried storing my xml parse values in a variable and then using that variable to insert data, even that does not works. I used the variable like this:
for($i=0; $i<=$x->length-1; $i++)
{
$zz=$z->item($i)->nodeValue);
$ww=$w->item($i)->nodeValue);
$yy=$y->item($i)->nodeValue);
$sql="INSERT INTO Persons (FirstName, LastName, Age) VALUES('$zz','$ww','$yy')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
}
My xml looks like this:
<RTAP>
<RECORD>
<TITLE> </TITLE>
<PRIMARY_AUTHOR> </PRIMARY_AUTHOR>
<JOURNAL_CONFERENCE> </JOURNAL_CONFERENCE>
</RECORD>
</RTAP>
Kindly help me, what should I do in this
Best Zeeshan