title: How to insert data from an HTML form into MySQL
body: <p>Please tell me what's wrong with my code!!!!</p>
  
  <p>new-payment.php</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;Process New Payment&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;h1&gt;Please Input Payment Details&lt;/h1&gt;
  &lt;fieldset&gt;
      &lt;legend&gt;New Payment&lt;/legend&gt;
      &lt;form action="process-payment.php" method="post" /&gt;
  &lt;table&gt;
  &lt;tr&gt;
  &lt;td&gt;Date:&lt;/td&gt;&lt;td&gt;&lt;input type="date" name="date" /&gt;&lt;br /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Today's Charge:&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="charge" /&gt;&lt;br /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Today's Payment:&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="payment" /&gt;&lt;br /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Client Number:&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="client_no" /&gt;&lt;br /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Client Name:&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="client_name" /&gt;&lt;br /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Check Number:&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="check_no" /&gt;&lt;br /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Check Amount:&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="check" /&gt;&lt;br /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Cash Amount:&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="cash" /&gt;&lt;br /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Notes:&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="notes" /&gt;&lt;br /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Staff Initials:&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="staff_initials" /&gt;&lt;br /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;input type="submit" value="Process Payment"&gt;
      &lt;/form&gt;
  &lt;/fieldset&gt;
  &lt;br /&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>process-payment.php</p>
  
  <pre><code>&lt;?php
  
  define('DB_NAME', 'DBNAME');
  define('DB_USER', 'USERNAME');
  define('DB_PASS', '');
  define('DB_HOST', 'localhost');
  
  $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
  
  if (!$link) {
      dir('There was a problem when trying to connect to the host. Please contact Tech Support. Error: ' . mysql_error());    
  }
  
  $db_selected = mysql_select_db(DB_NAME, $link);
  
  if (!$link) {
      dir('There was a problem when trying to connect to the database. Please contact Tech Support. Error: ' . mysql_error());    
  }
  
  $date = $_POST['date'];
  $charge = $_POST['charge'];
  $payment = $_POST['payment'];
  $client_no = $_POST['client_no'];
  $client_name = $_POST['client_name'];
  $check_no = $_POST['check_no'];
  $check = $_POST['check'];
  $cash = $_POST['cash'];
  $notes = $_POST['notes'];
  $staff_initials = $_POST['staff_initials'];
  
  $sql = "INSERT INTO payments (date, charge, payment, client_no, client_name, check_no, check, cash, notes, staff_initials) VALUES ('$date', '$charge', '$payment', '$client_no', '$client_name', '$check_no', '$check', '$cash', '$notes', '$staff_initials')";
  
  if (!mysql_query($sql)) {
      die('Error: ' . mysql_error()); 
  }
  
  ?&gt;
  </code></pre>
  
  <p>I do not know what is wrong but I get an error when I press Process Payment:</p>
  
  <blockquote>
    <p>Error: 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 'check, cash, notes, staff_initials) >VALUES ('2012-09-24', '$0.00', '$20.00', '46' at line 1</p>
  </blockquote>