Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    712
    Thanks
    165
    Thanked 0 Times in 0 Posts

    Strict Standards: Non-static method DOMDocument::load() should not be called sta

    Hi...
    I tried to import to my database an xml file using this code:
    PHP Code:
    <?php
    //ini_set('display_errors', -1);
    //error_reporting(E_ALL);
    //error_reporting(-1);
    error_reporting(E_ALL E_STRICT);
    //error_reporting(E_ALL ^ E_NOTICE); 
      
    date_default_timezone_set("Asia/Singapore"); //set the time zone    
    $data = array();

    $con mysql_connect("localhost""root","");
    if (!
    $con) { 
      die(
    mysql_error());
    }
    $db mysql_select_db("mes"$con);
    if (!
    $db) { 
      die(
    mysql_error());
    }
     
      
    function 
    add_employee($ETD,$PO_No,$SKUCode,$Description,$POReq ,$Comp)
      {
          global 
    $data;
          
          
          
    $con mysql_connect("localhost""root","");
          if (!
    $con){ die(mysql_error());}
          
    $db mysql_select_db("mes"$con);
          if (!
    $db) { 
              die(
    mysql_error());
          }

          
    $ETD$ETD;
          
    $PO_No $PO_No;
          
    $SKUCode $SKUCode;
          
    $Description $Description;
          
    $POReq $POReq;
          
    $Comp $Comp;
         

          
    $sql "INSERT INTO sales_order (ETD,PO_No,SKUCode,Description,POReq,Comp) 
          VALUES 
          ('$ETD','$PO_No','$SKUCode','$Description','$POReq','$Comp')
          ON DUPLICATE KEY UPDATE
          ETD = '$ETD', PO_No = '$PO_No', SKUCode = '$SKUCode', Description = '$Description', POReq = '$POReq', Comp = '$Comp'" 
    or die(mysql_error());
          
    $res mysql_query($sql$con);
          
           
    $data []= array('ETD'=>$ETD,'PO_No'=>$PO_No,'SKUCode'=>$SKUCode,'Description'=>$Description,'POReq'=>$POReq,'Comp'=>$Comp); 
    }
     
    // if (isset($_FILES['file']['tmp_name'])){
      

      
    if(empty($_FILES['file']['tmp_name']['error'])){
         
    $dom = new DOMDocument();
          
    $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 )
              {
                  
    $ETD "";
                  
    $PO_No "";
                  
    $SKUCode "";
                  
    $Description "";
                  
    $POReq "";
                  
    $Comp "";
                  
                  
    $index 1;
                  
    $cells $row->getElementsByTagName'Cell' );
              
                  foreach( 
    $cells as $cell )
                  { 
                      
    $ind $cell->getAttribute'Index' );
                      if ( 
    $ind != null $index $ind;

                      if ( 
    $index == $ETD $cell->nodeValue;  
                      if ( 
    $index == $PO_No $cell->nodeValue;
                      if ( 
    $index == $SKUCode $cell->nodeValue;
                      if ( 
    $index == $Description $cell->nodeValue;
                      if ( 
    $index == $POReq $cell->nodeValue;
                      if ( 
    $index == $Comp $cell->nodeValue;
                                        
    $index += 1;
                  }

                 if (
    $ETD=='' AND $PO_No=='' AND $SKUCode=='' AND $Description=='' AND $POReq=='' AND $Comp=='') {  
                        
    $last_row true;
                  }      
                  else {
                        
    add_employee($ETD,$PO_No,$SKUCode,$Description$POReq$Comp);  
                  }      
              }
              if (
    $last_row==true) {
                  
    $first_row true;
              }     
              else {
                  
    $first_row false;
              }
          }
      }  

     
      
    ?>
    but I got an error:

    Strict Standards: Non-static method DOMDocument::load() should not be called statically

    in this part:

    $dom = DOMDocument::load('SalesOrder.xml');

    I hope somebody can help me...I need to import data from .xml to my database.

    Thank you so much
    Last edited by newphpcoder; 04-25-2012 at 09:07 AM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    Check the example at http://php.net/manual/en/domdocument.load.php to see the usage.

    :: operator is used to invoke static functions. You need to use -> here.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    newphpcoder (04-25-2012)

  • #3
    Regular Coder
    Join Date
    Aug 2010
    Posts
    712
    Thanks
    165
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    Check the example at http://php.net/manual/en/domdocument.load.php to see the usage.

    :: operator is used to invoke static functions. You need to use -> here.
    You mean this:

    Code:
    $doc = new DOMDocument();
    $doc->load('book.xml');
    $doc->saveXML();
    Thank you

  • #4
    Regular Coder
    Join Date
    Aug 2010
    Posts
    712
    Thanks
    165
    Thanked 0 Times in 0 Posts
    i tried:

    Code:
    if(empty($_FILES['file']['tmp_name']['error'])){
         //$dom = new DOMDocument();
         //$dom = DOMDocument::load('SalesOrder.xml');
         $dom = new DOMDocument();
    $dom->load('SalesOrder.xml');
    $dom->saveXML();
       
      // $dom = DOMDocument::load($_FILES['file']['tmp_name']);
      //  $dom = DOMDocument::__construct();           
          $rows = $dom->getElementsByTagName('Row');
          global $last_row;
          $last_row = false;
          $first_row = true;
    No error but it did not save to my database the data

    Thank you

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    We can't really help you here. This assumes that $dom->getElementsByTagName finds valid tags under the name Row in the default namespace. If the namespace isn't default you need to change your handling to deal with the namespaces.
    This snippet doesn't contain near enough information either. Where's the code to insert? global shouldn't ever be used except where you cannot modify the function signature required by a callback script, but this appears to be global in the main method. If so, this will have no value here.
    Are you trying to pull data from one file into another? The commented out section appears to be trying this, but the current section doesn't include this functionality. You only have one $dom established. Depending on what you are attempting to do, this could be a simple importNode from the uploaded file into the salesorder.xml file.

  • Users who have thanked Fou-Lu for this post:

    newphpcoder (04-26-2012)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •