title: PHP Variable in mysql call $sql( SELECT * FROM Example WHERE Example = "$example" )
body: <p>I have a form that allows people to add Soldiers to the list which is transferred to mysql just fine. It's even fine if I do it without a variable but once I try and added one like below.</p>
  
  <pre><code>// Get Variable from LocalStorage (This has been tested and does indeed return fine)
  $affiliation = "&lt;script&gt;document.write(localStorage.getItem('join_affiliation'));&lt;/script&gt;";
  
  $sql = 'SELECT * FROM Reenactors WHERE Affiliation="'. $affiliation.'"';
  </code></pre>
  
  <p>It doesn't want to work. This code is used display's a table of all Affiliation related Soliders on the review page. I'm at a complete lost and not sure what to do at this point. I hope someone out there can help me out. Below is the full list of PHP code.</p>
  
  <pre><code>$affiliation = "&lt;script&gt;document.write(localStorage.getItem('join_affiliation'));&lt;/script&gt;";
  
  // REMOVED USER AND PASSWORD OF COURSE :D
  $con = mysql_connect("localhost","USERNAME","PASSWORD");
  if (!con){ die("Can not connect: " . mysql_error()); } 
  
  
  mysql_select_db("grainger_2013", $con);
  $sql = 'SELECT * FROM Reenactors WHERE Affiliation="'$affiliation'"';
  $myData = mysql_query($sql, $con);
  
  // ECHO TABLE CONTENTS      
  while($row = mysql_fetch_array($myData)){
      echo "&lt;tr&gt;";
      echo "&lt;td&gt;" . $row['ID'] . "&lt;/td&gt;";
      echo "&lt;td&gt;" . $row['Side'] . "&lt;/td&gt;";
      echo "&lt;td&gt;" . $row['Role'] . "&lt;/td&gt;";
      echo "&lt;td&gt;" . $row['First_Name'] . "&lt;/td&gt;";
      echo "&lt;td&gt;" . $row['Last_Name'] . "&lt;/td&gt;";
      echo "&lt;/tr&gt;";
  }
  
  // TEST VARIABLE (Does work)
  echo '&lt;p&gt;' . $affiliation . '&lt;/p&gt;';
  
  mysql_close($con);
  </code></pre>
  
  <hr>
  
  <p>WORKS...</p>
  
  <pre><code>$sql = 'SELECT * FROM Reenactors WHERE Affiliation = "TEST"';
  </code></pre>
  
  <p>DOESN'T WORK...</p>
  
  <pre><code>$sql = 'SELECT * FROM Reenactors WHERE Affiliation = "' $affiliation '"';
  
  $sql = 'SELECT * FROM Reenactors WHERE Affiliation = "' . $affiliation . '"';
  
  $sql = 'SELECT * FROM Reenactors WHERE Affiliation = "' . mysql_real_escape_string($affiliation) . '"';
  
  $sql = sprintf("SELECT * FROM Reenactors WHERE Affiliation= '%s'",mysql_real_escape_string($affiliation));
  
  $sql = "SELECT * FROM Reenactors WHERE Affiliation LIKE \"$affiliation\"";
  
  $sql = "SELECT * FROM Reenactors WHERE Affiliation = \"$affiliation \"";
  </code></pre>