PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 12th, 2012, 03:26 AM
bullex bullex is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 bullex User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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) > ) {
            
            
$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'")) < ) {
                
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' ) ? 0;
        
mysql_query("UPDATE `products` SET stock='$stock', price='$price', published='$published' WHERE id='$product_id'");
    }
    
?>DONE

Reply With Quote
  #2  
Old December 12th, 2012, 07:18 AM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,907 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 1 Month 1 Day 8 h 11 m 37 sec
Reputation Power: 581
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.

Reply With Quote
  #3  
Old December 12th, 2012, 06:23 PM
msteudel's Avatar
msteudel msteudel is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Sep 2002
Location: Seattle, U.S.A.
Posts: 712 msteudel User rank is Lance Corporal (50 - 100 Reputation Level)msteudel User rank is Lance Corporal (50 - 100 Reputation Level)msteudel User rank is Lance Corporal (50 - 100 Reputation Level) 
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.

Reply With Quote
  #4  
Old December 13th, 2012, 04:33 AM
bullex bullex is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 bullex User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #5  
Old December 13th, 2012, 07:03 AM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,907 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 1 Month 1 Day 8 h 11 m 37 sec
Reputation Power: 581
You need to explain what "does not work" means.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Import data from xml file to database

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap