I want to upload several files (fileName1, fileName2, fileName3, etc ...) which contain xml data into mysql table (tblName) at once.
The xml data structure is as follows:
<tagName>
<field1></field1>
<field2></field2>
<field3></field3>
<field4></field4>
</tagName>
Actually, I want to upload these files directly from the local computer to the web server, but I'm still learning how it applies to custom button.
For simplicity, while I use the data upload menu by creating a new table called tblFile (id, nmfile) even though I don't actually need these files to be on the web server.
In the before record added event, I added the following:
$fileArray = my_json_decode($values["nmfile"]);
for($i = 0; $i < count($fileArray); $i++){
$fileuploaded = $fileArray[$i]["name"];
$xml = simplexml_load_file($fileuploaded);
foreach ($xml->children() as $row) {
$field1 = $row->field1;
$field2 = $row->field2;
$field3 = $row->field3;
$field4 = $row->field4;
$sql = "INSERT INTO tblName(field1, field2, field3, field4) VALUES ('".$field1."','".$field2."','".$field3."','".$field4."')";
$rs = DB::Query($sql);
}
}
Problem:
After the application is run, the code above only manages to move data from just one file into myssql (tblName), which is the xml data in fileName1. Meanwhile, the xml data in the table fileName2, fileName3, etc. ... is not uploaded to mysql.
Is there anything that was missed in the above event
Any solution would be appreciated.