title: How to save data from an HTML form to a database table in WordPress?
body: <p>I have a WordPress theme, and I'm trying to save data from an HTML form into a database.</p>
  
  <p>I made the HTML form and added a "save &amp; close" button which calls a JavaScript function named <code>saveData()</code> that takes the data from the form and sends it to <code>addrow.php</code>, which should save the data into a database table named <code>vel</code>.</p>
  
  <p>I think the problem is in <code>addrow.php</code> because in WordPress, one needs to use the global <code>$wpdb</code> or some other thing.</p>
  
  <p>What would be a simple example be for how to save data from an HTML form into a database table in a WordPress-powered application?</p>
  
  <p>The <code>addrow.php</code> code:</p>
  
  <pre><code>&lt;?php
      require("phpsqlinfo_dbinfo.php");
  
      // Gets data from URL parameters
      $nombre = $_GET['nombre'];
      $direccion = $_GET['direccion'];
      $lat = $_GET['lat'];
      $lng = $_GET['lng'];
      $tipo = $_GET['tipo'];
  
      // Opens a connection to a MySQL server
      $connection = mysql_connect ("localhost", $username, $password);
      if (!$connection) {
          die('Not connected : ' . mysql_error());
      }
  
      // Set the active MySQL database
      $db_selected = mysql_select_db($database, $connection);
      if (!$db_selected) {
          die ('Can\'t use db : ' . mysql_error());
      }
  
      // Insert new row with user data
      $query = sprintf("INSERT INTO vel " .
      " (id, nombre, direccion, lat, lng, tipo ) " .
      " VALUES (NULL, '%s', '%s', '%s', '%s', '%s');",
      mysql_real_escape_string($nombre),
      mysql_real_escape_string($direccion),
      mysql_real_escape_string($lat),
      mysql_real_escape_string($lng),
      mysql_real_escape_string($tipo));
  
      $result = mysql_query($query);
  
      if (!$result) {
          die('Invalid query: ' . mysql_error());
      }
  ?&gt;
  </code></pre>