Title: Update Query not working
Last modified: August 20, 2016

---

# Update Query not working

 *  [hhelmbold](https://wordpress.org/support/users/hhelmbold/)
 * (@hhelmbold)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/update-query-not-working/)
 * I have the following code :
 *     ```
       function update_comp_count($lead_id, $sp_value, $field_number) {
           global $wpdb;
   
           $lead_detail_table = RGFormsModel::get_lead_details_table_name();
   
           $sql = $wpdb->prepare(" UPDATE $lead_detail_table SET value = %d WHERE lead_id = %d AND field_number = %d)", $sp_value, $lead_id, $field_number);
   
           $wpdb->query($sql);
   
       }
       ```
   
 * I use similiar code for Inserting data into the database :
 *     ```
       $lead_detail_table = RGFormsModel::get_lead_details_table_name();
   
       	for ($i = 0; $i <= 6; $i++) {
       		$sql = $wpdb->prepare(" INSERT INTO $lead_detail_table (lead_id, form_id, field_number, value)
       								VALUES (%d, 7, %s, %s
       								)", $lead_id, $new_stud_values[$i]->field, $new_stud_values[$i]->value);
       		$wpdb->query($sql);
       	}
       ```
   
 * The insert code works perfectly but the Update code doesn’t work at all. Any 
   ideas on this?

Viewing 1 replies (of 1 total)

 *  Thread Starter [hhelmbold](https://wordpress.org/support/users/hhelmbold/)
 * (@hhelmbold)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/update-query-not-working/#post-2228195)
 * I figured I had an extra “)” in my code…

Viewing 1 replies (of 1 total)

The topic ‘Update Query not working’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [hhelmbold](https://wordpress.org/support/users/hhelmbold/)
 * Last activity: [14 years, 10 months ago](https://wordpress.org/support/topic/update-query-not-working/#post-2228195)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
