Title: $wpdb-&gt;update not working
Last modified: August 21, 2016

---

# $wpdb->update not working

 *  Resolved [Snaphaan](https://wordpress.org/support/users/snaphaan/)
 * (@snaphaan)
 * [12 years ago](https://wordpress.org/support/topic/wpdb-update-not-working/)
 * This is a small part of a plugin I am working on that adds some user input to
   the DB.
 * The following is not working at all:
 *     ```
       <?php if($_POST['submit']) {
   
       	global $wpdb;
   
       	$preek_naam = $_POST['preek_naam'];
       	$preek_gemeente = $_POST['preek_gemeente'];
       	$preek_teks = $_POST['preek_teks'];
   
       	$wpdb->update('bible_afri', array('preke' => $preek_teks), array('index' => 1), array('%s')); 
   
       		}
       ```
   
 * but if I replace `array('preke' => $preek_teks)` with array(‘preke’ => “some 
   text here”)` it loads it into the DB!
 * I have no idea why.

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

 *  [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * (@catacaustic)
 * [12 years ago](https://wordpress.org/support/topic/wpdb-update-not-working/#post-4858656)
 * You need to do some basic debugging here.
 * You’ve said that when you change the value ot be some text instead of the value
   from the form, it updats correctly. So that tells me that there’s something wrong
   with whatever value is being retrieved from the form.
 *     ```
       global $wpdb;
   
       $preek_naam = $_POST['preek_naam'];
       $preek_gemeente = $_POST['preek_gemeente'];
       $preek_teks = $_POST['preek_teks'];
   
       echo '<p>$preek_teks = "'.$preek_teks.'"</p>';
   
       $result = $wpdb->update('bible_afri', array('preke' => $preek_teks), array('index' => 1), array('%s'));
   
       if( $result === false) {
           // ERROR!
           echo '<p>DB insert error - '.$wpdb->print_error().'</p>';
       }
       ```
   
 * That will show you want the value is, and if there’s an error inserting it, then
   it will show the error. Remember to take the extra parts out of the code when
   you’re finished as you don’t want that to be shown to the public. 🙂
 *  Thread Starter [Snaphaan](https://wordpress.org/support/users/snaphaan/)
 * (@snaphaan)
 * [12 years ago](https://wordpress.org/support/topic/wpdb-update-not-working/#post-4858731)
 * I think I found the problem.
 * For some reason I changed the <submit> name to “stuur” and never made the same
   changes to `if($_POST['submit'])`. I’ve changed both back to submit… less confusion!
 * Thanks for the help!

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

The topic ‘$wpdb->update not working’ is closed to new replies.

## Tags

 * [$wpdb-&gt;update](https://wordpress.org/support/topic-tag/wpdb-gtupdate/)
 * [database](https://wordpress.org/support/topic-tag/database/)
 * [db](https://wordpress.org/support/topic-tag/db/)

 * 2 replies
 * 2 participants
 * Last reply from: [Snaphaan](https://wordpress.org/support/users/snaphaan/)
 * Last activity: [12 years ago](https://wordpress.org/support/topic/wpdb-update-not-working/#post-4858731)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
