title: Using a variable as the column name in a mysql query
body: <p>I'm trying to turn this:</p>
  
  <pre><code>"SELECT username FROM $table WHERE username='$newName'"
  </code></pre>
  
  <p>Into this:</p>
  
  <pre><code>"SELECT $column FROM $table WHERE $column='$newName'"
  </code></pre>
  
  <p>But when I use <code>or die()</code> on it, I get an error saying that there is incorrect syntax near <code>WHERE username='someNameHere'</code>. What is the correct way to substitute the column name, assuming that's what's wrong?</p>
  
  <p><strong>Edit:</strong> Code is just this. The values should be correct as I don't see any mispellings in the error.</p>
  
  <pre><code>$sql = "SELECT $column FROM $table WHERE $column='$newName'";
  $result = mysql_query($sql) or die( mysql_error());
  </code></pre>