title: Send form data to WordPress database table
body: <p>I am trying to build a plugin that will allow the admin to add data about a particular package ( just like creating User). In the front end I will have a form that will allow the visitors to search for a particular package using an id that was assigned to that package by the admin.</p>
  
  <p>I built the system using php and its working fine. Now I want to turn it into a WordPress plugin, and I am finding it hard to send the form data to wpdb table that was created when the plugin was activated (wp_demo). </p>
  
  <p>This is the form:</p>
  
  <pre><code>function registration_init(){
      echo '&lt;form action="demo.php" method="post" /&gt;';
      echo "&lt;h1&gt;Britchi Tracking&lt;/h1&gt;";
      echo '&lt;p&gt;';
      echo 'Costumers Name (required) &lt;br/&gt;';
      echo '&lt;input type="text" name="cname" placeholder="Emmanuel John"/&gt;';
      echo '&lt;/p&gt;';
      echo '&lt;p&gt;';
      echo 'Tracking number (required) &lt;br/&gt;';
      echo '&lt;input type="text" name="ctracking" placeholder="EEX28PDS"/&gt;';
      echo '&lt;/p&gt;';
      echo '&lt;p&gt;';
      echo 'Email (required) &lt;br/&gt;';
      echo '&lt;input type="email" name="cemail" placeholder="Email"/&gt;';
      echo '&lt;/p&gt;';
      echo '&lt;p&gt;';
      echo 'Recived Port (required) &lt;br/&gt;';
      echo '&lt;input type="text" name="crport" placeholder="Brazil Port"/&gt;';
      echo '&lt;/p&gt;';
      echo '&lt;p&gt;';
      echo 'Delivered Port (required) &lt;br/&gt;';
      echo '&lt;input type="text" name="cdport" placeholder="Lagos Port"/&gt;';
      echo '&lt;/p&gt;';
      echo '&lt;p&gt;';
      echo 'Current Location (required) &lt;br/&gt;';
      echo '&lt;input type="text" name="clocation" placeholder="Abuja" /&gt;';
      echo '&lt;/p&gt;';
      echo '&lt;p&gt;';
      echo 'Destination (required) &lt;br/&gt;';
      echo '&lt;input type="text" name="cdestination" placeholder="Total filling Station, Abuja"/&gt;';
      echo '&lt;/p&gt;';
      echo '&lt;p&gt;&lt;input type="submit" name="cregistered" value="Register"&gt;&lt;/p&gt;';
      echo '&lt;/form&gt;';
  }
  </code></pre>
  
  <p>This is the form processing code:</p>
  
  <pre><code>&lt;?php
  
  define('DB_NAME', 'wordpree2');
  define('DB_USER', 'root');
  define('DB_PASSWORD', 'chimezie12');
  define('DB_HOST', 'localhost');
  
  $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
  
  if (!$link) {
      die('Could not connect: ' . mysql_error());
      error_reporting(E_ALL);
      ini_set('display_errors', 1);
  }
  
  $db_selected = mysql_selected_db(DB_NAME, $link);
  
  if (!$db_select) {
      die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
  }
  
  $cname = $_POST['cname'];
  $cemail = $_POST['cemail'];
  $ctracking = $_POST['ctracking'];
  $crport = $_POST['crport'];
  $cdport = $_POST['cdport'];
  $clocation = $_POST['clocation'];
  $cdestination = $_POST['cdestination'];
  
  $sql = "INSERT INTO `wp_demo` (cname, cemail, ctracking, erport, cdport, clocation, cdestination) VALUES ('$cname', '$cemail', '$ctracking', '$crport', '$cdport', '$clocation', '$cdestination')";
  
  if (!mysql_query($sql)) {
      die('ERROR: ' . mysql_error());
  }
  
  mysql_close();
  ?&gt;
  </code></pre>
  
  <p>I know this is not the correct way to insert data to wpdb table, but I don't know how else to do it.</p>