{"id":4610005,"date":"2014-02-13T17:36:13","date_gmt":"2014-02-13T17:36:13","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/write-a-row-to-database-table-via-button-or-link\/"},"modified":"2016-08-21T16:16:50","modified_gmt":"2016-08-21T16:16:50","slug":"write-a-row-to-database-table-via-button-or-link","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/write-a-row-to-database-table-via-button-or-link\/","title":{"rendered":"Write a row to database table via button or link"},"content":{"rendered":"<p>When someone clicks a specific button on my page i&#8217;m looking to grab a few pieces of data (user name, date\/time, URI, etc.) and write a row into a table I created in the wordpress mySQL database.<\/p>\n<p>I can successfully write to my database using this:<\/p>\n<pre><code>&lt;?php\n    global $wpdb;\n\n    \/\/ Get URL\n    $Path=$_SERVER[&#039;REQUEST_URI&#039;];\n    $URI=&#039;http:\/\/www.example.com&#039;.$Path;\n\n    \/\/ Get Current User\n    $user = wp_get_current_user();\n\n    \/\/ Inject row into custom_table\n    $wpdb-&gt;insert(\n    &#039;custom_table&#039;,\n    array(\n        &#039;user&#039; =&gt; $user-&gt;user_login,\n        &#039;page&#039; =&gt; $URI,\n        &#039;vote&#039; =&gt; 6,\n        &#039;date&#039; =&gt; current_time(&#039;mysql&#039;)),\n    array(\n        &#039;%s&#039;,\n        &#039;%s&#039;,\n        &#039;%d&#039;,\n        &#039;%s&#039;\n    )\n);\n?&gt;<\/code><\/pre>\n<p>How can I make this action happen upon a button click?<\/p>\n","protected":false},"template":"","class_list":["post-4610005","topic","type-topic","status-closed","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/4610005","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/4610005\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=4610005"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}