The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Import data from xml file to database
Discuss Import data from xml file to database in the PHP Development forum on Dev Shed. Import data from xml file to database PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 12th, 2012, 03:26 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 3
Time spent in forums: 1 h 15 m 32 sec
Reputation Power: 0
|
|
|
Import data from xml file to database
I need a little help for a script theat makes a import in to a table from 2 xml files .
The probles is theat i could do the insert from the first xml file but when i try to import data from the second xml ( the update script) does not work.
PHP Code:
<?php
error_reporting(E_ALL ^ E_NOTICE);
ini_set('display_errors', 1);
ini_set('max_execution_time', 999999999);
require_once('config.php');
require_once('functions.php');
require_once('class.GetProd.php');
$html = file_get_contents('xml/cezar5423.xml');
$GetProd = new GetProd();
$GetProd->parameters = array('TYPE', 'BRAND', 'TITLE', 'VOLUME', 'SEX', 'NOTE', 'SET', 'PICTURE', 'EAN', 'DAMAGED', 'TESTER');
$product = $GetProd->processing($html);
foreach ( $product as $product_id => $val ) {
$sefurl = sefurl($product[$product_id]['TITLE']);
if ( strlen($sefurl) > 0 ) {
$type = mysql_real_escape_string(trim($product[$product_id]['TYPE']));
$brand = mysql_real_escape_string(trim($product[$product_id]['BRAND']));
$title = mysql_real_escape_string(trim($product[$product_id]['TITLE']));
$volume = mysql_real_escape_string(trim($product[$product_id]['VOLUME']));
$sex = mysql_real_escape_string(trim($product[$product_id]['SEX']));
$note = mysql_real_escape_string(trim($product[$product_id]['NOTE']));
$set = mysql_real_escape_string(trim($product[$product_id]['SET']));
$ean = mysql_real_escape_string(trim($product[$product_id]['EAN']));
$damaged = mysql_real_escape_string(trim($product[$product_id]['DAMAGED']));
$tester = mysql_real_escape_string(trim($product[$product_id]['TESTER']));
$date = date('Y-m-d H:i:s', time());
if ( mysql_num_rows(mysql_query("SELECT * FROM `products` WHERE id='$product_id'")) < 1 ) {
mysql_query("INSERT INTO products (`id`, `sku`, `name`, `producer`, `type`, `volume`, `sex`, `note`, `set`, `damaged`, `tester`, `image`, `sefurl`, `created`) VALUES ('$product_id', '$ean', '$title', '$brand', '$type', '$volume', '$sex', '$note', '$set', '$damaged', '$tester', '$sefurl', '$sefurl', '$date')");
}
}
}
$html = file_get_contents('xml/cezar54233.xml');
$GetProd->parameters = array('PRICE', 'AVAILABILITY', 'STOCK');
$product = $GetProd->processing($html);
foreach ( $product as $product_id => $val ) {
$stock = $product[$product_id]['STOCK'];
$price = $product[$product_id]['PRICE'];
$published = ( $product[$product_id]['AVAILABILITY'] == 'in stock' ) ? 1 : 0;
mysql_query("UPDATE `products` SET stock='$stock', price='$price', published='$published' WHERE id='$product_id'");
}
?>DONE
|

December 12th, 2012, 07:18 AM
|
|
|
|
1) Please edit your post and wrap your code in [ PHP ] tags not [ QUOTE ] tags. See the sticky at the top of the forum.
2) Please indent your code to make it more readable.
3) Switch to PDO as the MySQL extensions are deprecated.
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.
|

December 12th, 2012, 06:23 PM
|
 |
Contributing User
|
|
Join Date: Sep 2002
Location: Seattle, U.S.A.
Posts: 712
 
Time spent in forums: 4 Days 11 h 4 m 59 sec
Reputation Power: 11
|
|
|
Have you validated both XML files? Maybe there's something in the second xml file that breaks the import process.
|

December 13th, 2012, 04:33 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 3
Time spent in forums: 1 h 15 m 32 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by msteudel Have you validated both XML files? Maybe there's something in the second xml file that breaks the import process. |
Yes i validated both XML files, the $product variable contains value form xml file.
|

December 13th, 2012, 07:03 AM
|
|
|
|
You need to explain what "does not work" means.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|