I have a custom html form from which I am trying to insert records into a custom table .My problem is getting the current user name and inserting that value into the custom table. When the user clicks the Submit button the code below should fire. This is my php code:
<?php> session_start; require_once "wp-load.php"; require_once "dbconfig.php"; global $wpdb, $current_user; $current_user=wp_get_current_user(); $table_name="persons"; $wpdb->insert( $table_name, array( 'first_name' => $_POST['first_name'], 'last_name' => $_POST['last_name'], 'email' => $_POST['email'], 'telephone' => $_POST['telephone'], 'user_name' => [$current_user] ) ); ?>
Any help is greatly appreciated. Been working on this for hours now, unable to find the solution.
Thanks in advance.