I have a registration form in my wordpress site. I used the following code to insert the user.
$username = $wpdb->escape(trim($_POST['txtFullName']));
$email = $wpdb->escape(trim($_POST['txtEmail']));
$password = $wpdb->escape(trim($_POST['txtPassword']));
$confirmpassword = $wpdb->escape(trim($_POST['txtConfirmPassword']));
$gender = $wpdb->escape(trim($_POST['gender']));
$user_id = wp_insert_user( array ('user_pass' => apply_filters('pre_user_user_pass', $password), 'user_login' => apply_filters('pre_user_user_login', $username), 'user_email' => apply_filters('pre_user_user_email', $email), 'role' => 'author' ) );
I used the following code to get the inserted id under the above line.
$authid = $wpdb->insert_id;
AUTO_INCREMENT primary key in the user table varies from the inserted id. I couldn’t track the error. How to fix this?
wp_insert_user()returns the ID of the newly created user. In your example$user_idalready contains the new ID.