/    Sign up×
Community /Pin to ProfileBookmark

Problem in uploading .xml file where not all row will be import to the database

Hi..

I have code for importing .xml file to database.

the problem is I cannot upload my file but no error display. And also I got a problem in importing data from .xml file to database but not all row will be save.

here is my code:

[code=php]
<?php
$data = array();

$con = mysql_connect(“localhost”, “root”,””);
if (!$con) {
die(mysql_error());
}
$db = mysql_select_db(“mes”, $con);
if (!$db) {
die(mysql_error());
}

$sql = “select * from sales_order”;
$result = mysql_query($sql);
if (!$result) {
die(mysql_error());
}

function add_employee($ProductType,$WorkOrder,$POIssueDate,$SalesMonth)
{
global $data;

$con = mysql_connect(“localhost”, “root”,””);
if (!$con){ die(mysql_error());}
$db = mysql_select_db(“mes”, $con);
if (!$db) {
die(mysql_error());
}

$ProductType= $ProductType;
$WorkOrder = $WorkOrder;
$POIssueDate = $POIssueDate;
$SalesMonth = $SalesMonth;

$sql = “INSERT INTO sales_order (ProductType,WorkOrder,POIssueDate,SalesMonth)
VALUES
(‘$ProductType’,’$WorkOrder’,’$POIssueDate’,’$SalesMonth’)” or die(mysql_error());
mysql_query($sql, $con);

$data []= array(‘ProductType’=>$ProductType,’WorkOrder’=>$WorkOrder,’POIssueDate’=>$POIssueDate,’SalesMOnth’=>$SalesMonth);
}
if ( $_FILES[‘file’][‘tmp_name’] [‘error’])
//f (empty($_FILES[‘file’][‘tmp_name’][‘error’]))
{ //$dom = DOMDocument::load(‘SalesOrder.xml’);
$dom = DOMDocument::load($_FILES[‘file’][‘tmp_name’]);
$dom = DOMDocument::__construct();
$rows = $dom->getElementsByTagName(‘Row’);
global $last_row;
$last_row = false;
$first_row = true;
foreach ($rows as $row)
{
if ( !$first_row )
{
$ProductType = “”;
$WorkOrder = “”;
$POIssueDate = “”;
$SalesMonth = “”;

$index = 1;
$cells = $row->getElementsByTagName( ‘Cell’ );

foreach( $cells as $cell )
{
$ind = $cell->getAttribute( ‘Index’ );
if ( $ind != null ) $index = $ind;

if ( $index == 1 ) $ProductType = $cell->nodeValue;
if ( $index == 2 ) $WorkOrder = $cell->nodeValue;
if ( $index == 3 ) $POIssueDate = $cell->nodeValue;
if ( $index == 4 ) $SalesMonth = $cell->nodeValue;
$index += 1;
}

if ($ProductType==” AND $WorkOrder==” AND $POIssueDate==” AND $SalesMonth==”) {
$last_row = true;
}
else {
add_employee($ProductType,$WorkOrder,$POIssueDate,$SalesMonth);
}
}
if ($last_row==true) {
$first_row = true;
}
else {
$first_row = false;
}
}
}
?>

<html>
<body>
<table>
<tr>
<th>Sales Order</th>
</tr>
<?php foreach( $data as $row ) { ?>
<tr>
<td><?php echo( $row[‘ProductType’] ); ?></td>
<td><?php echo( $row[‘WorkOrder’] ); ?></td>
<td><?php echo( $row[‘POIssueDate’]) ;?> </td>
<td><?php echo( $row[‘SalesMonth’] ); ?></td>
</tr>
<?php } ?>
</table>
</body>
</html>
[/code]

and I will attach my sample data and the data with color yellow background is only row I want to save to my database.

Thank you so much..

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @newphpcoder spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...