title: When to surround SQL fields with apostrophes?
body: <p>I notice that when I <code>INSERT</code> and <code>SELECT</code> values to and from a database I have to surround the fields with single quotes, like so:</p>
  
  <p><code>mysql_query("INSERT INTO employees (name, age) VALUES ('$name', '$age')");</code></p>
  
  <p>However, if I were to update the age, I would not use single quotes:</p>
  
  <p><code>mysql_query("UPDATE employees SET age = age + 1 WHERE name = '$name'");</code></p>
  
  <p>Also, it seems when adding the date to a SQL database I do not have to surround it with single quotes either:</p>
  
  <p><code>mysql_query("INSERT INTO employees (name, date) VALUES ('$name', NOW())");</code></p>
  
  <p>Also, when using operators like CONCAT it seems not to be necessary either:</p>
  
  <p><code>mysql_query("UPDATE employees SET name=CONCAT(name,$lastName) WHERE id='$id'");</code></p>
  
  <p>Perhaps I am just coding poorly but I seem to recall if I did not surround a field with single quotes when inserting and selecting it the operation failed.</p>