I've got a WordPress theme, and I am attempting to save data from an HTML form right into a database.

I made the HTML form and added a "save &lifier close" button which calls a JavaScript function named saveData() that can take the information in the form and transmits it to addrow.php, that ought to save the information right into a database table named vel.

I believe the issue is in addrow.php because in WordPress, one should make use of the global $wpdb as well as other factor.

What will be a simple example be based on how in order to save data from an HTML form right into a database table inside a WordPress-powered application?

The addrow.php code:



    // Will get data from URL parameters

    $nombre = $_GET['nombre']

    $direccion = $_GET['direccion']

    $lat = $_GET['lat']

    $lng = $_GET['lng']

    $tipo = $_GET['tipo']

    // Opens an association to some MySQL server

    $connection = mysql_connect ("localhost", $username, $password)

    if (!$connection) 

    // Set the active MySQL database

    $db_selected = mysql_choose_db($database, $connection)

    if (!$db_selected) 

    // Place new row with user data

    $query = sprintf("Place INTO vel " .

    " (id, nombre, direccion, lat, lng, tipo ) " .

    " VALUES (NULL, '%s', '%s', '%s', '%s', '%s')",






    $result = mysql_query($query)

    if (!$result) 


You're correct to be able to place data right into a database table, it's a best practice to make use of $wpdb. The WordPress Codex can present you with good examples and much more information that will help you proceed.

For instance, to place a brand new record right into a database table, this can be done (in the above linked page):

$wpdb->insert( 'table', array( 'column1' => 'value1', 'column2' => 123 ), array( '%s', '%d' ) )

Should you publish additional code (e.g., so how exactly does addrow.php presently attempt to save the information?), we may have the ability to provide more specific information.