title: Accessing $wpdb in new Wordpress PHP file, "require wp-load.php" NOT working
body: <p>Alright, I've been pretty frustrated with accessing $wpdb in a new PHP file in WordPress.  Now, I've gone through and read all the answers I could find on the situation, and they're all universal in saying that all I need to do is add wp-load.php at the top of my php file which uses $wpdb and it should work.  I've done that...  However, it still isn't working.  To make sure I'm not doing anything stupid, I've included both files in their entirety.  Here's my code:</p>
  
  <p>main-admin.php:</p>
  
  <pre><code>&lt;?php    
  function my_plugin_menu(){
              add_menu_page('my System', 'my System','administrator', 'my-plugin.php', 'my_plugin_action', plugins_url('my.png', __FILE__));
         }
  
      function my_plugin_action(){
        ?&gt;
      &lt;form id="createItemForm" method="post"&gt;
        &lt;br/&gt;&lt;br/&gt;Create New Item
      &lt;table&gt;&lt;tr&gt;
      &lt;td&gt;Enter Item Name:&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="itemName" id="itemName"&gt;&lt;/td&gt;&lt;/tr&gt;&lt;br&gt;&lt;tr&gt;
      &lt;td&gt;Enter Item Value: &lt;/td&gt;&lt;td&gt;&lt;input type="text" name="itemValue" id="itemValue"&gt;&lt;/td&gt;&lt;/tr&gt;&lt;br&gt;&lt;tr&gt;
       &lt;td&gt;&lt;input type="submit" class="button button-primary" id="specialSubmit2" value="Create Item"&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
      &lt;/form&gt;
      &lt;script&gt;
      jQuery(function() {
          jQuery('#createItemForm').submit(function(e){
              e.preventDefault();
              var itemName = jQuery( "input[id='itemName']" ).val();
              var itemValue = jQuery("input[id='itemValue']").val();
              alert(itemName + " " + itemValue);//Test that it works, it does
              jQuery.ajax({
                  type: "POST",
                  url: "../path/to/submit.php",
                  data:{ name: itemName, value: itemValue }, 
                  success: function(data){
                      alert(data);
                  },
                  error: function (req, textStatus, thrownError) {
                          console.log(req.responseText);
                      }
                      });
                  });
              });
          &lt;/script&gt;
          &lt;?php 
      } 
      ?&gt;
  </code></pre>
  
  <p>submit.php (within same folder):</p>
  
  <pre><code>&lt;?php
  require_once( 'path/to/wp-load.php' );
  if(isset($_POST["name"]) &amp;&amp; isset($_POST["value"])){
    global $wpdb;
    $varCheckCon = $wpdb-&gt;check_connection();
    echo json_encode($varCheckCon);
  }
  ?&gt;
  </code></pre>
  
  <p>However, all it does is return me a 500 error, not even a "false" for not connected.  It should be noted that the main-admin.php file itself is not the core WordPress plugin PHP file (that main file can access $wpdb without any problems).  Rather, both main-admin.php and submit.php are new PHP files that I've made within a /admin subfolder within my WordPress plugin.  The main-admin.php form appears as part of my dashboard menu in Wordpress; it is called from the main file.</p>
  
  <p>I'm still something of a Wordpress beginner, so maybe it's something incredibly stupid that I'm missing?</p>
  
  <p>Thanks for any help!</p>