title: PHP Form upload to MySQL Database
body: <p>PHP beginner working from a tutorial.  I'm trying to do a simple upload from a PHP form to a MySQL database.  The form uploads correctly, but every time the page refreshes, it repeats the previous upload, creating duplicate entries.  You can see my working page <a href="http://thenally.com/work/database/index.php" rel="nofollow">here</a>.</p>
  
  <p>You can see that I'm trying to get the comment "Thank you! Product Added!" to spit out above the table upon submission, but I'll admit that I'm confused as to exactly what is happening when I hit "Submit"...right now it always shows the confirmation message!  I've included the PHP code for the form below.</p>
  
  <p>Thanks in advance!</p>
  
  <p>Mike</p>
  
  <pre><code>&lt;div id="form"&gt;
  
  &lt;h1 class="green"&gt;UPLOAD TO TABLE 'manufacturer'&lt;/h1&gt;
  
  
  &lt;?php
  
  $con = mysql_connect($host,$user,$pass);
  if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
  
  mysql_select_db("thenally_productdump", $con);
  
  $sql="INSERT INTO manufacturer (manu_name, manu_product_type, manu_product_description, manu_website)
  VALUES
  ('$_POST[manufacturer]','$_POST[product]','$_POST[description]','$_POST[website]')";
  
  if (!mysql_query($sql,$con))
    {
    die('Error: ' . mysql_error());
    }
  echo "Thank you! Product Added!";
  
  mysql_close($con);
  
  ?&gt; 
  
  &lt;form action="" method="post"&gt;
  &lt;table&gt;
      &lt;tr&gt;
      &lt;td class="form-table-left"&gt;&lt;b&gt;Manufacturer: &lt;/b&gt; &lt;/td&gt;
      &lt;td class="form-table-right"&gt;&lt;input type="text" name="manufacturer" size=50&gt;&lt;/td&gt;
      &lt;/tr&gt;
  
      &lt;tr&gt;
      &lt;td class="form-table-left"&gt;&lt;b&gt;Product Type:&lt;/b&gt;&lt;/td&gt;
      &lt;td class="form-table-right"&gt;&lt;input type="text" name="product" size=50&gt;&lt;/td&gt;
      &lt;/tr&gt;
  
      &lt;tr&gt;
      &lt;td class="form-table-left"&gt;&lt;b&gt;Product Description: &lt;/b&gt;&lt;/td&gt;
      &lt;td class="form-table-right"&gt;&lt;textarea name="description" rows=5 cols=40&gt;&lt;/textarea&gt;&lt;/td&gt;
      &lt;/tr&gt;
  
      &lt;tr&gt;
      &lt;td class="form-table-left"&gt;&lt;b&gt;Manufacturer Website: &lt;/b&gt;&lt;/td&gt;
      &lt;td class="form-table-right"&gt;&lt;input type="text" name="website" value="http://" size=50&gt;&lt;/td&gt;
      &lt;/tr&gt;
  
      &lt;tr&gt;
      &lt;td class="submit"&gt;&lt;input type="submit" name="submit" value="Add Product !"&gt;&lt;/td&gt;
      &lt;/tr&gt;
  
      &lt;/table&gt;
      &lt;/form&gt;
  
  &lt;/div&gt;
  </code></pre>