form input submit to database using $wpdb

admin

Administrator
Staff member
I am wondering how to insert form input value to wordpress database.
In a wordpress theme, I want to add an input element and insert it to database.
Clicking the submit button, I think there is no effect to insert for the following codes.

<h1>wordpress_theme_file.php</h1>

Code:
&lt;form id=”form_reply” action=”database.php” method=”post”&gt;
…
&lt;input type=”text” id=”newValue” name=”newValue” /&gt;
…
&lt;/form&gt;

<h1>database.php</h1>

Code:
&lt;?php
global $wpdb;
$inputValue = $_POST[‘ newValue ‘];
$wpdb-&gt;insert(‘wp_table_name’, ‘field_name’=&gt;$inputValue);  // wp_table_name and field_name in database
?&gt;