title: How can I insert php variables in a sql query?
body: <p>I've found a lot of answers for this that don't seem to work for me.
  When I have apostrophes around the variables $message and $email and $date like</p>
  
  <pre><code>    'VALUES ('$message', '$email', '$date')';
  </code></pre>
  
  <p>it tells me </p>
  
  <blockquote>
    <p>Parse error: syntax error, unexpected '$message' (T_VARIABLE)</p>
  </blockquote>
  
  <p>When I remove them, I get something like Could not enter data: Unknown column '$message' in 'field list'. I've tried to insert</p>
  
  <pre><code>    $message = mysql_real_escape_string($message);    
      $email = mysql_real_escape_string($email);
      $date = mysql_real_escape_string($date);
  </code></pre>
  
  <p>with " " around the variables like</p>
  
  <pre><code>'VALUES ("$message", "$email", "$date")';
  </code></pre>
  
  <p>which gets rid of the error message but now, instead of the input from the html form, i'm getting literally "$message" in my database.</p>
  
  <p>What is it that I'm doing wrong?
  My simple objective is just to take an email, a message, and the date, and put it in a database. Please help! Thank you!</p>
  
  <p>Here is the complete code I have:</p>
  
  <pre><code>     &lt;?php
  if($_POST &amp;&amp; isset($_POST['email'], $_POST['essay'])) {
  
  
      $dbhost = 'localhost';
      $dbuser = 'root';
      $dbpass = 'password';
  
      $conn=mysql_connect($dbhost, $dbuser);
      if(! $conn)
      {
          die('Could not connect: ' . mysql_error());
      }
  
      mysql_select_db("Ink", $conn);
  
      date_default_timezone_set("America/New_York");
      $message = $_POST['essay'];
      $email = $_POST['email'];
      $date = date("y-m-d h:i:sa");
  
  
      $sql = 'INSERT INTO inktable '.
              '(writings, email, date) '.
              'VALUES ('$message', '$email', '$date')';
  
      mysql_select_db('ink');
      $retval = mysql_query($sql, $conn);
      if(! $retval)
      {
          die('Could not enter data: ' .mysql_error());
      }
  
      mysql_close($conn);
  }
  ?&gt;
  </code></pre>