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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    713
    Thanks
    165
    Thanked 0 Times in 0 Posts

    Problem in uploading .xml file where not all row will be import to the database

    Hi..

    I have code for importing .xml file to database.

    the problem is I cannot upload my file but no error display. And also I got a problem in importing data from .xml file to database but not all row will be save.

    here is my code:

    Code:
    <?php
    $data = array();
    
    $con = mysql_connect("localhost", "root","");
    if (!$con) { 
      die(mysql_error());
    }
    $db = mysql_select_db("mes", $con);
    if (!$db) { 
      die(mysql_error());
    }
    
      $sql = "select * from sales_order";
    $result =  mysql_query($sql);
    if (!$result) {
        die(mysql_error());
    }
      
    function add_employee($ProductType,$WorkOrder,$POIssueDate,$SalesMonth)
      {
          global $data;
          
          
          $con = mysql_connect("localhost", "root","");
          if (!$con){ die(mysql_error());}
          $db = mysql_select_db("mes", $con);
          if (!$db) { 
              die(mysql_error());
          }
    
          $ProductType= $ProductType;
          $WorkOrder = $WorkOrder;
          $POIssueDate = $POIssueDate;
          $SalesMonth = $SalesMonth;
             
          $sql = "INSERT INTO sales_order (ProductType,WorkOrder,POIssueDate,SalesMonth) 
          VALUES 
          ('$ProductType','$WorkOrder','$POIssueDate','$SalesMonth')" or die(mysql_error());
          mysql_query($sql, $con);
          
          
          $data []= array('ProductType'=>$ProductType,'WorkOrder'=>$WorkOrder,'POIssueDate'=>$POIssueDate,'SalesMOnth'=>$SalesMonth);
      }
      if ( $_FILES['file']['tmp_name'] ['error'])
     //f (empty($_FILES['file']['tmp_name']['error']))  
      { //$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 )
              {
                  $ProductType = "";
                  $WorkOrder = "";
                  $POIssueDate = "";
                  $SalesMonth = "";
                  
                  $index = 1;
                  $cells = $row->getElementsByTagName( 'Cell' );
              
                  foreach( $cells as $cell )
                  { 
                      $ind = $cell->getAttribute( 'Index' );
                      if ( $ind != null ) $index = $ind;
                  
                      if ( $index == 1 ) $ProductType = $cell->nodeValue;  
                      if ( $index == 2 ) $WorkOrder = $cell->nodeValue;
                      if ( $index == 3 ) $POIssueDate = $cell->nodeValue;
                      if ( $index == 4 ) $SalesMonth = $cell->nodeValue;
                      $index += 1;
                  }
    
                 if ($ProductType=='' AND $WorkOrder=='' AND $POIssueDate=='' AND $SalesMonth=='') {  
                        $last_row = true;
                  }      
                  else {
                        add_employee($ProductType,$WorkOrder,$POIssueDate,$SalesMonth);  
                  }      
              }
              if ($last_row==true) {
                  $first_row = true;
              }     
              else {
                  $first_row = false;
              }
          }
      }
      ?>
      
      <html>
      <body>
      <table>
      <tr>
          <th>Sales Order</th>
      </tr>
      <?php foreach( $data as $row ) { ?>
      <tr>
      <td><?php echo( $row['ProductType'] ); ?></td>
      <td><?php echo( $row['WorkOrder'] ); ?></td>
      <td><?php echo( $row['POIssueDate']) ;?> </td>
      <td><?php echo( $row['SalesMonth'] ); ?></td>
      </tr>
      <?php } ?>
      </table>
      </body>
     </html>
    and I will attach my sample data and the data with color yellow background is only row I want to save to my database.

    Thank you so much..
    Attached Thumbnails Attached Thumbnails Problem in uploading .xml file where not all row will be import to the database-salesorderimg.jpg  

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    This is the very first problem:
    PHP Code:
    if ( $_FILES['file']['tmp_name'] ['error']) 
    The $_FILES offset won't have an error listed under that level. It is $_FILES['file']['error']. If it were correct, that indicates there is an error, yet you attempt to open and parse the file. Successful uploads result in UPLOAD_ERR_OK which is equivalent to 0, which in turn is equivalent to false. Any other result is caused by a failure code.


  •  

    Posting Permissions

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