www.webdeveloper.com
Results 1 to 2 of 2

Thread: Problem in uploading .xml file

  1. #1
    Join Date
    Oct 2011
    Posts
    350

    Problem in uploading .xml file

    Good day!

    I have code for uploading the files with the extension name .xml, after it was upload it will display in webpage and also save to database...

    My problem is during on my testing ...When I upload .xml file it did not upload, No error displayed...Sometimes when I upload it will upload, but theres a .xml file that did not upload, I cannot configured why it happens.

    here is the code:
    PHP Code:
    <?php
    $data 
    = array();


    $con mysql_connect("localhost""root","");
    if (!
    $con) { 
      die(
    mysql_error());
    }
    $db mysql_select_db("hris"$con);
    if (!
    $db) { 
      die(
    mysql_error());
    }

    $sql "select * from attendance";
    $result =  mysql_query($sql$con);
    if (!
    $result) {
        die(
    mysql_error());
    }
    $total mysql_num_rows($result);
    if (
    $total 0) {
        
    $sql "delete from attendance";
        
    $result =  mysql_query($sql$con);
        if (!
    $result) {
            die(
    mysql_error());
        }
    }
      
    function 
    add_employee($EMP_NO$Lastname$Firstname$Middlename$Date$Time)
      {
          global 
    $data
          
          
    $con mysql_connect("localhost""root","");
          if (!
    $con){ die(mysql_error());}
          
    $db mysql_select_db("hris"$con);
          if (!
    $db) { 
              die(
    mysql_error());
          }

          
    $EMP_NO $EMP_NO;
          
    $Lastname $Lastname;
          
    $Firstname $Firstname;
          
    $Middlename $Middlename;
          
    $Date substr($Date,0,-13);
          
    $Time substr($Time,11,-4);

          
    $Time strftime('%I:%M %p'strtotime($Time));


               
          
    $sql "INSERT INTO attendance (EMP_NO, Lastname, Firstname, Middlename, Date, Time) VALUES ('$EMP_NO', '$Lastname', '$Firstname', '$Middlename', '$Date', '$Time')";
          
    mysql_query($sql$con);
          
       
          
    $data []= array('EMP_NO' => $EMP_NO'Lastname' => $Lastname'Firstname' => $Firstname'Middlename' => $Middlename'Date' => $Date'Time' => $Time);
          
      }
      
      if ( 
    $_FILES['file']['tmp_name'] )
      {
          
    $dom DOMDocument::load$_FILES['file']['tmp_name'] );
                  
          
    $rows $dom->getElementsByTagName'Row' );
          global 
    $last_row;
          
    $last_row false;
          
    $first_row true;
          foreach (
    $rows as $row)
          {
              if ( !
    $first_row )
              {
                 
                  
    $EMP_NO "";
                  
    $Lastname "";
                  
    $Firstname "";
                  
    $Middlename "";
                  
    $Date "";
                  
    $Time "";
                  
                  
                  
    $index 1;
                  
    $cells $row->getElementsByTagName'Cell' );
              
                  foreach( 
    $cells as $cell )
                  { 
                      
    $ind $cell->getAttribute'Index' );
                      if ( 
    $ind != null $index $ind;
                      
                      if ( 
    $index == $EMP_NO $cell->nodeValue;
                      if ( 
    $index == $Lastname $cell->nodeValue;
                      if ( 
    $index == $Firstname $cell->nodeValue;
                      if ( 
    $index == $Middlename $cell->nodeValue;
                      if ( 
    $index == $Date $cell->nodeValue;
                      if ( 
    $index == $Time $cell->nodeValue;
                      
    $index += 1;
                  }
             
                  if (
    $EMP_NO=='' and $Lastname=='' and $Firstname=='' and $Middlename=='' and $Date=='' and $Time=='') {
                        
    $last_row true;
                  }      
                  else {
                      
                        
    add_employee($EMP_NO$Lastname$Firstname$Middlename$Date$Time);
                  }      
              }
              if (
    $last_row==true) {
                  
    $first_row true;
              }     
              else {
                  
    $first_row false;
              }
          }
      }
      
    ?>
      
      <html>
      <body>
      <table>
      <tr>
          <th>Employee Attendance</th>
      </tr>

      <?php foreach( $data as $row ) { ?>
      <tr>
      <td><?php echo( $row['EMP_NO'] ); ?></td> 
      <td><?php echo( $row['Lastname'] ); ?></td>
      <td><?php echo( $row['Firstname'] ); ?></td>
      <td><?php echo( $row['Middlename'] ); ?></td>
      <td><?php echo( $row['Date'] ); ?></td>
      <td><?php echo( $row['Time'] ); ?></td>
      </tr>
      <?php ?>
      </table>
      </body>
     </html>
    Thank you

  2. #2
    Join Date
    Jul 2010
    Location
    /ramdisk/
    Posts
    865
    Turn error reporting on

    also something like this:
    $_FILES['file']['error'] should contain a description of the error,

    No disc space left, etc. Lol (I never considered having no disc space left, but that should throw an exception or something).

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles