title: How to properly INSERT INTO MySQL Using PHP Variables
body: <p>I'm having a problem with my personal server where I'm trying to create a database for the decade old binders I have for the Yu-Gi-Oh! Trading Card Game (haven't played in years). In testing the INSERT INTO, I keep running across a particular problem...</p>
  
  <blockquote>
    <p>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Magic'(Name, Description, Card_ID, Pack, P_ID, Quantity) VALUES ('Post', 'Post ' at line 1</p>
  </blockquote>
  
  <p>Now my code outputs properly when I comment out the query function and echo to my webpage, but I keep getting the above mysql_error() message being displayed.</p>
  
  <p>My code snippet is as follows...</p>
  
  <pre><code>if(isset($_SESSION['username'])) {
  mysql_connect("localhost", "my_username", "my_password") or die(mysql_error());
  mysql_select_db("my_db") or die(mysql_error());
  
  function clean_string($value) {
      if(get_magic_quotes_gpc() ) {
              $value = stripslashes($value);
      }
      return mysql_real_escape_string($value);
  }
  
  $Show = clean_string($_POST['show']);
  $Table = clean_string($_POST['table']);
  $Insert_M_T = $_POST['insert_magic_traps'];
  $Insert_Monster = $_POST['insert_monster_effect'];
  
  $Insert_Card_Type = clean_string($_POST['I_Type']);
  $Insert_Card_Name = clean_string($_POST['I_Card_Name']);
  $Insert_Description = clean_string($_POST['I_C_Description']);
  $Insert_Card_ID = clean_string($_POST['I_Card_ID']);
  $Insert_CardPack = clean_string($_POST['I_C_Pack']);
  $Insert_PackID = clean_string($_POST['I_C_P_ID']);
  $Insert_Quantity = clean_string($_POST['I_C_Quantity']);
  
  if(isset($Insert_M_T)) {
      $sql = "INSERT INTO '$Insert_Card_Type'(Name, Description, Card_ID, Pack, P_ID, Quantity) VALUES ('$Insert_Card_Name', '$Insert_Description', '$Insert_Card_ID', '$Insert_CardPack', '$Insert_PackID', '$Insert_Quantity')";
      mysql_query($sql) or die(mysql_error());
      echo "&lt;center&gt;&lt;h2&gt;Record added to Table: $Insert_Card_Type&lt;/h2&gt;&lt;/center&gt;";
      echo "&lt;center&gt;&lt;table&gt;&lt;tr&gt;&lt;th&gt;Name:&lt;/th&gt;&lt;td&gt;$Insert_Card_Name&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;Description:&lt;/th&gt;&lt;td&gt;$Insert_Description&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;Card ID:&lt;/th&gt;&lt;td&gt;$Insert_Card_ID&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;Pack:&lt;/th&gt;&lt;td&gt;$Insert_CardPack&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;Pack ID Number&lt;/th&gt;&lt;td&gt;$Insert_PackID&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;Quantity:&lt;/th&gt;&lt;td&gt;$Insert_Quantity&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/center&gt;";
  }
  ?&gt;
  //more html and php code
  &lt;?php
  } else {
      echo "&lt;h1&gt;&lt;center&gt;&lt;font color=#ff0000 &gt;ACCESS DENIED!!!&lt;/font&gt;&lt;/center&gt;&lt;/h1&gt;";
      echo "&lt;h2&gt;&lt;center&gt;&lt;a href=index.php &gt;Login Here!&lt;/a&gt;&lt;/center&gt;&lt;/h2&gt;";
  }
  ?&gt;
  </code></pre>
  
  <p>Any advice would be helpful. I've tried searching for how to get around this problem, but to no avail. I feel like this is a simple fix, but I'm missing it. Please advise.</p>
  
  <p>Thank you in advance.</p>
  
  <p>~DanceLink</p>