Title: Users select/insert | wpdb
Last modified: May 10, 2024

---

# Users select/insert | wpdb

 *  Resolved [pwpx2](https://wordpress.org/support/users/pwpx2/)
 * (@pwpx2)
 * [2 years ago](https://wordpress.org/support/topic/users-select-insert-wpdb/)
 * Hi All,
 * It’s my first time since a very, very long time using wordpress again and I have
   some issues with a function I want to create to automate a cronjob.
 * I’m trying to select the users i have from wp_users table and insert a few values
   into another table on the same database, but different table (users).
 * I’ve got so far with this code, but when i run it nothing happens. Not even an
   error.
 * Any suggestions are welcomed. Thank you
 *     ```wp-block-code
       function wp_users_table_bind(){
       global $wpdb;
       $secret = mksecret();
       $added = time();
       $status = 'confirmed';
   
       $result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}users" );
   
       foreach( $result as $results ){
       $name = $results['user_login'];
       $passhash = $results['user_pass'];
       $email = $results['user_email'];
       }
   
       $wpdb->query("INSERT INTO users (username, passhash, secret, email, status, added) VALUES ($name, $passhash, $secret, $email, $status, $added) 
       ON DUPLICATE KEY UPDATE 
       username = $name,
       passhash = $passhash,
       secret = $secret,
       email = $email,
       status = $status,
       added = $added");
       $wpdb->insert_id;
       }
       ```
   

Viewing 1 replies (of 1 total)

 *  Thread Starter [pwpx2](https://wordpress.org/support/users/pwpx2/)
 * (@pwpx2)
 * [2 years ago](https://wordpress.org/support/topic/users-select-insert-wpdb/#post-17747433)
 * fixed. modified the code. can be deleted.

Viewing 1 replies (of 1 total)

The topic ‘Users select/insert | wpdb’ is closed to new replies.

## Tags

 * [query](https://wordpress.org/support/topic-tag/query/)
 * [users](https://wordpress.org/support/topic-tag/users/)
 * [wpdb](https://wordpress.org/support/topic-tag/wpdb/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 1 participant
 * Last reply from: [pwpx2](https://wordpress.org/support/users/pwpx2/)
 * Last activity: [2 years ago](https://wordpress.org/support/topic/users-select-insert-wpdb/#post-17747433)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
