title: PHP import an XML file into a database
body: <p>I am attempting to allow users to upload a file, the contents of which would then be read into a database using SimpleXML. My code is as follows:</p>
  
  <pre><code>else
  {
      $info = pathinfo($_FILES['xml_file']['tmp_name']);
      $extension = $info['extension'];
  
      if($extension != 'xml')
      {
          flash_message($lang-&gt;wiki_invalid_file, 'error');
          admin_redirect('index.php?module=wiki-import');
      }
      else
      {
          if($_FILES['xml_file']['error'] == UPLOAD_ERR_OK &amp;&amp; is_uploaded_file($_FILES['xml_file']['tmp_name']))
          {
              $string = file_get_contents($_FILES['xml_file']['tmp_name']);
              $xml = new SimpleXMLElement($string);
              foreach($xml-&gt;article as $article)
              {
                  $query = "INSERT INTO " . TABLE_PREFIX . "wiki('authors','title','content','protected','lastauthor','lastauthorid','category') VALUES('" . $article-&gt;authors . "','" . $article-&gt;title . "','" . $article-&gt;content . "','" . $article-&gt;protected . "','" . $article-&gt;lastauthor . "','" . $article-&gt;lastauthorid . "','" . $article-&gt;category . "',)";
                  $sql = $db-&gt;write_query($query);
                  if($db-&gt;error_number() &gt; 0)
                  {
                      flash_message($lang-&gt;wiki_import_error, 'error');
                      admin_redirect('index.php?module=wiki-import');
                  }
                  elseif(!$sql)
                  {
                      flash_message($lang-&gt;wiki_import_error, 'error');
                      admin_redirect('index.php?module=wiki-import');
                  }
                  else
                  {
                      flash_message($lang-&gt;wiki_import_success, 'success');
                      admin_redirect('index.php?module=wiki-import');
                  }
              }
          }
          else
          {
              flash_message($lang-&gt;wiki_import_error, 'error');
              admin_redirect('index.php?module=wiki-import');
          }
      }
  }
  </code></pre>
  
  <p>(I am using MyBB, which has definitions for <code>flash_message</code> and <code>admin_redirect</code>, which redirects the user to another page and displays a message.)</p>
  
  <p>My issue is that I cannot seem to upload it at all, no error message is shown. In addition, the page just refreshes. A sample piece of content is:</p>
  
  <pre><code>&lt;?xml version="1.0" ?&gt;
  &lt;wiki&gt;
      &lt;article&gt;
          &lt;id&gt;1&lt;/id&gt;
          &lt;title&gt;To be Exported&lt;/title&gt;
          &lt;content&gt;
              Export me!
          &lt;/content&gt;
          &lt;category&gt;Meta&lt;/category&gt;
          &lt;lastauthor&gt;admin&lt;/lastauthor&gt;
          &lt;lastauthorid&gt;1&lt;/lastauthorid&gt;
          &lt;protected&gt;0&lt;/protected&gt;
          &lt;authors&gt;1&lt;/authors&gt;
      &lt;/article&gt;
  &lt;/wiki&gt;
  </code></pre>
  
  <p>The <code>id</code> and <code>name</code> attribute of the file upload box is 'xml_file'. I also have PHP version 5.3.13 on my localhost.</p>