#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep 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
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,452
    Rep Power
    594
    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.
  4. #3
  5. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2002
    Location
    Seattle, U.S.A.
    Posts
    712
    Rep Power
    12
    Have you validated both XML files? Maybe there's something in the second xml file that breaks the import process.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0
    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.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,452
    Rep Power
    594
    You need to explain what "does not work" means.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.

IMN logo majestic logo threadwatch logo seochat tools logo