WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] $wpdb->update not working (3 posts)

  1. Snaphaan
    Member
    Posted 4 months ago #

    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.

  2. catacaustic
    Member
    Posted 4 months ago #

    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. :)

  3. Snaphaan
    Member
    Posted 3 months ago #

    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!

Reply

You must log in to post.

About this Topic