• Resolved Snaphaan

    (@snaphaan)


    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)
  • 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

    (@snaphaan)

    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.