title: MySQL error: Incorrect Table Name
body: <p>I'm pretty new to web development so there's a good chance I'm doing something pretty dumb here.</p>
  
  <p>I'm using AJAX to send data to a PHP file which will use the data to run SQL commands to update a table. I'm dealing with editing articles, so my PHP file needs to know three things: The original name of the article (for reference), the new name and the new content. I also tell it what page the user is looking at so it knows which table to edit.</p>
  
  <pre><code>    $('#save_articles').click(function () {
  
      var current_page = $('#current_location').html();
      var array_details = {};
      array_details['__current_page__'] = current_page;
  
          $('#article_items .article_title').each(function(){
  
              var article_name = $(this).html(); //The text in this div is the element name
              var new_article_name = $(this).next('.article_content');
              new_article_name = $(new_article_name).children('.article_content_title').html();
              var new_article_content = $(this).next('.article_content');
              new_article_content = $(new_article_content).children('.article_content_content').html();
  
              array_new_deets = {new_name:new_article_name, content:new_article_content};
              array_details[article_name] = array_new_deets;
  
          });
  
          send_ajax("includes/admin/admin_save_articles.php", array_details);
  
      });
  </code></pre>
  
  <p>In the PHP file, I first retrieve the current page and store it in $sql_table and then remove the current page variable from $_POST. Then I run this.</p>
  
  <pre><code>foreach($_POST as $key =&gt; $value){
  
          $original_name = $key;
          $new_name = $value['new_name'];
          $new_cont = $value['content'];
  
  
          $query =    "UPDATE 
                          `$sql_table`
                      SET 
                          `element_name`= '$new_name',
                          `element_content` = '$new_cont',
                      WHERE
                          `element_name` = '$original_name'";
  
          $query = mysql_query($query);
  
  
          if(!$query){
  
                  die(mysql_error());
  
              }
  
      }
  </code></pre>
  
  <p>I always receive an error saying that 'sitep_Home' is an incorrect table name. Not only is it a real table in my db, but I've actually changed its name to make sure it isn't an issue with keywords or something.</p>
  
  <p>If I instead run the query without the variable $sql_table (specifying that the table is called 'sitep_Home'), the query accepts the table. It then doesn't actually update the table, and I suspect it's because of the WHERE argument that also uses a variable.</p>
  
  <p>Can anyone see what I'm doing wrong here?</p>