newphpcoder Posted April 25, 2012 Share Posted April 25, 2012 Hi... I tried to import to my database an xml file using this 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 == 1 ) $ETD = $cell->nodeValue; if ( $index == 2 ) $PO_No = $cell->nodeValue; if ( $index == 3 ) $SKUCode = $cell->nodeValue; if ( $index == 4 ) $Description = $cell->nodeValue; if ( $index == 5 ) $POReq = $cell->nodeValue; if ( $index == 6 ) $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 Quote Link to comment https://forums.phpfreaks.com/topic/261569-strict-standards-non-static-method-domdocumentload-should-not-be-called-sta/ Share on other sites More sharing options...
trq Posted April 25, 2012 Share Posted April 25, 2012 Your creating an object then never using it. You then try and call load() directly from a class, it's not static, so you shouldn't. Change: $dom = new DOMDocument(); $dom = DOMDocument::load('SalesOrder.xml'); to $doc = new DOMDocument; $dom = $doc->load('SalesOrder.xml'); Quote Link to comment https://forums.phpfreaks.com/topic/261569-strict-standards-non-static-method-domdocumentload-should-not-be-called-sta/#findComment-1340346 Share on other sites More sharing options...
newphpcoder Posted April 25, 2012 Author Share Posted April 25, 2012 I tried this: if(empty($_FILES['file']['tmp_name'])){ // $dom = new DOMDocument(); //$dom = DOMDocument::load('SalesOrder.xml'); // $dom = new DOMDocument(); //$dom->load('SalesOrder.xml'); $doc = new DOMDocument; $dom = $doc->load('SalesOrder.xml'); //$dom->saveXML(); // $dom = DOMDocument::load($_FILES['file']['tmp_name']); // $dom = DOMDocument::__construct(); $rows = $dom->getElementsByTagName('Row'); yet I got an error: Fatal error: Call to a member function getElementsByTagName() on a non-object Thank you Quote Link to comment https://forums.phpfreaks.com/topic/261569-strict-standards-non-static-method-domdocumentload-should-not-be-called-sta/#findComment-1340347 Share on other sites More sharing options...
Zane Posted April 25, 2012 Share Posted April 25, 2012 You still have to call the constructor. .. ie.. use parenthesis. $dom = new DOMDocument(); Quote Link to comment https://forums.phpfreaks.com/topic/261569-strict-standards-non-static-method-domdocumentload-should-not-be-called-sta/#findComment-1340348 Share on other sites More sharing options...
newphpcoder Posted April 25, 2012 Author Share Posted April 25, 2012 I tried this: $doc = new DOMDocument(); $dom = $doc->load('SalesOrder.xml'); //$dom->saveXML(); // $dom = DOMDocument::load($_FILES['file']['tmp_name']); // $dom = DOMDocument::__construct(); $rows = $doc->getElementsByTagName('Row'); global $last_row; solved my problem Quote Link to comment https://forums.phpfreaks.com/topic/261569-strict-standards-non-static-method-domdocumentload-should-not-be-called-sta/#findComment-1340350 Share on other sites More sharing options...
trq Posted April 25, 2012 Share Posted April 25, 2012 You still have to call the constructor. .. ie.. use parenthesis. There is no need for parenthesis unless you need to pass arguments. The problem is in the variable naming. $dom = new DOMDocument; $dom->load('SalesOrder.xml'); $rows = $dom->getElementsByTagName('Row'); Probably my fault but I wasn't looking at how load worked. There is no need to save the result into a variable. Quote Link to comment https://forums.phpfreaks.com/topic/261569-strict-standards-non-static-method-domdocumentload-should-not-be-called-sta/#findComment-1340351 Share on other sites More sharing options...
Zane Posted April 25, 2012 Share Posted April 25, 2012 There is no need for parenthesis unless you need to pass arguments. Never knew that, I figured it was a typo. Quote Link to comment https://forums.phpfreaks.com/topic/261569-strict-standards-non-static-method-domdocumentload-should-not-be-called-sta/#findComment-1340352 Share on other sites More sharing options...
newphpcoder Posted April 26, 2012 Author Share Posted April 26, 2012 Yes, ur right thats the solution.. Thank you for your help.. Quote Link to comment https://forums.phpfreaks.com/topic/261569-strict-standards-non-static-method-domdocumentload-should-not-be-called-sta/#findComment-1340563 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.