title: Insert value from select box into database
body: <p>I have a post text website on <a href="http://www.youngcreatitivy.se" rel="nofollow">http://www.youngcreatitivy.se</a></p>
  
  <p>You see on <a href="http://www.youngcreativity.se/post.php" rel="nofollow">http://www.youngcreativity.se/post.php</a> that I have a post method. And on the bottom of the page I have like a option to choose which category your text is in. I've founded this code for inserting value from select box into my database. Here it is:</p>
  
  <pre><code>&lt;?php
  
  
  //insert category to database
  if(isset($_POST['qty'])) {
  // Fetch and clean the &lt;select&gt; value.
  // The (int) makes sure the value is really a integer.
  $qty = (int)$_POST['qty'];
  
  // Create the INSERT query.
  $sql = "INSERT INTO `table`(`quantity`)
          VALUES ({$qty})";
  
  // Connect to a database and execute the query.
  $dbLink = mysql_connect('server', 'username', 'password') or     die(mysql_error());
            mysql_select_db('database_name', $dbLink) or die(mysql_errno());
  
  $result = mysql_query($sql);
  
  // Check the results and print the appropriate message.
  if($result) {
      echo "Record successfully inserted!";
  }
  else {
      echo "Record not inserted! (". mysql_error() .")";
  }
  }
  ?&gt;
  </code></pre>
  
  <p>Thats the Php code. </p>
  
  <p>Here's the html code:</p>
  
  <pre><code>     Qty: &lt;select name="category"&gt;
          &lt;option value="1"&gt;Quote&lt;/option&gt;
          &lt;option value="1"&gt;Poem&lt;/option&gt;
          &lt;option value="1"&gt;Novel&lt;/option&gt;
      &lt;/select&gt;
      &lt;br&gt;
      &lt;input type="submit"&gt;
      &lt;/select&gt;
  </code></pre>
  
  <p>I understand the code, but how should I create the database in phpMyAdmin? And how can I get so that If I click submit after choosing the category and typed in my text it post the text and it writes which category I chosen in the database?
  Please, help me! </p>