0

I have a plugin here that registers a user for my wordPress site but now I want to update the ID of the user that just registered after they submit a form.

I am trying to edit a plugin on WordPress that after it submits a form I should get the last inserted ID and update the records that were just added.

        <?php do_action( 'user_registration_form_registration_end', $form_id ); ?>
        <?php

           // Add refer 
           global $wpdb;

           $table_name  = $wpdb->prefix."users";
           $current_user = wp_get_current_user();
          // $lastid = $wpdb->insert_id;

           if(isset($_GET['ID'])){

               $where = array('ID' => $current_user);
               $subs = array('refID'=> $_GET['ref_id']);
               $wpdb->update($table_name, $subs, $where);
           } 


        ?>

    </form>

    <div style="clear:both"></div>
</div>

I want it to get a value from the url and then update the user record in the database.

iamatstackoverflow
  • 402
  • 2
  • 4
  • 13
  • 1
    Does this answer your question? [How to get last inserted row ID from WordPress database?](https://stackoverflow.com/questions/1576018/how-to-get-last-inserted-row-id-from-wordpress-database) – ttrasn Nov 03 '19 at 11:20

1 Answers1

0

You can do this as-it will return you the last inserted row

$sql="SELECT * FROM `table-name` ORDER BY id DESC LIMIT 1";
$result=mysqli_fetch_array($sql);
Reza Ghorbani
  • 2,396
  • 2
  • 28
  • 33