Title: Updating two database table when button clicked
Last modified: November 30, 2019

---

# Updating two database table when button clicked

 *  Resolved [TheXrion](https://wordpress.org/support/users/negarehgfx/)
 * (@negarehgfx)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/updating-two-database-table-when-button-clicked/)
 * I want to update two table in database after button clicked. Already Using a 
   update query separated but some times the second query will not run and not updating
   the table.
 * This is my code
 *     ```
       $wpdb->replace($table_name_users,$data_array_users);
       $wpdb->update($table_name,$data_array,$data_where);
       ```
   
 * What is the problem and how can i fix it out ?
    -  This topic was modified 6 years, 6 months ago by [TheXrion](https://wordpress.org/support/users/negarehgfx/).

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/updating-two-database-table-when-button-clicked/#post-12194497)
 * Intermittent problems are difficult to resolve unless you can find a way to reliably
   induce the error. Furthermore, you’ve not given us much to go on. What are the
   values in the passed variables which are known to fail?
 * Taking a wild guess, if the passed arrays contain values that should be stored
   as numeric, there could be issues with the resulting SQL query. Especially if
   the table fields are not all varchar. To be safe, you should pass corresponding
   format arrays for $data_array and $data_where. NB: $wpdb methods only support
   string, integer, or float formats.
 *  Thread Starter [TheXrion](https://wordpress.org/support/users/negarehgfx/)
 * (@negarehgfx)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/updating-two-database-table-when-button-clicked/#post-12194517)
 * In this case I tried to post just integer and strings like current user username
   
   Those queries will work 70% of the time. Let me explain what i guess : Arrays
   should be sort how the queries sorted ? Like this : 1 – First arrays of first
   query 2 – Second arrays of second query
 * Then queries should be written like this :
    1- First query that send first arrays
   2- Second query that send second arrays
 * Is this arrangement is important ?
    Cause in my case this arrangement has not
   been regarded.
    -  This reply was modified 6 years, 6 months ago by [TheXrion](https://wordpress.org/support/users/negarehgfx/).
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/updating-two-database-table-when-button-clicked/#post-12197479)
 * Your plan should work, provided everything was done correctly. If the supplied
   data involves integers I think it’s important to supply format field data when
   calling $wpdb methods. Only if everything were strings and varchar, can we safely
   omit them.
    [https://developer.wordpress.org/reference/classes/wpdb/update/](https://developer.wordpress.org/reference/classes/wpdb/update/)
   You should provide the $format and $format_where arguments in your call.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Updating two database table when button clicked’ is closed to new replies.

## Tags

 * [database](https://wordpress.org/support/topic-tag/database/)
 * [MySQL](https://wordpress.org/support/topic-tag/mysql/)
 * [wpdb](https://wordpress.org/support/topic-tag/wpdb/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 3 replies
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [6 years, 6 months ago](https://wordpress.org/support/topic/updating-two-database-table-when-button-clicked/#post-12197479)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
