• Resolved tobydecks

    (@tobydecks)


    Hi,

    I’m mucking around writing my first plugin for WP, but I’m stuck with the $wpdb object.

    The plugin creates a new table in the database, with the code I found in the Codex.

    Anyway, heres the code

    <?php
                global $wpdb;
            if($_POST['oscimp_hidden'] == 'Y') {
                $blogcat = $_POST['cat'];
                $imageurl =  $_POST['image_url'];
                $wpdb->update( 'wp_blogcathead', array( 'blogcat' => $blogcat, 'imageurl' => $imageurl ), array('%s', '%s'));
    
                ?>
    
                <div class="updated"><p><strong><?php _e('Options saved.' ); ?></strong></p></div>
    
    <?php        } else {
                //Normal page display
            }
        ?>
    <div class="wrap">
                <?php    echo "<h2>" . __( 'Blog Category Header Images', 'oscimp_trdom' ) . "</h2>"; ?>
    
                <form name="oscimp_form" method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>">
                    <input type="hidden" name="oscimp_hidden" value="Y">
                    <p>Select category: <?php wp_dropdown_categories(); ?></p>
                    <p>Image URL: <input type="text" name="image_url" size="20" value=""/></p>
    
                    <p class="submit">
                    <input type="submit" name="Submit" value="Click it!" />
                    </p>
                </form>
                <table>

    I don’t get an error, but it’s not writing the two variable values.

    Anyone know what I’ve missed?

    Thanks.

    PS I know the code is messy 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • Anonymous User

    (@anonymized-3085)

    have you actually checked the database? or are you assuming it hasn’t been saved as it doesn’t show up on the page? Because it doesn’t look like you are checking for the stored values.

    Thread Starter tobydecks

    (@tobydecks)

    Yeah. I was checking the database.

    Just realised I was being a total numpty.

    Fixed it now.

    Thanks anyway 🙂

    I have the following but can get the update part to work. any reason why?

    $cmtval = 3250;

    $querycommentsOfUrltoUpdate = $wpdb->get_results(
    “SELECT comment_karma FROM
    $wpdb->comments
    WHERE comment_ID = $cmtval
    And comment_post_ID = 787″);
    //start loop
    foreach ( $querycommentsOfUrltoUpdate as $querycommentsOfUrltoUpdates){
    $currentvoteplus = $querycommentsOfUrltoUpdates->comment_karma +1;
    }
    //end loop

    $wpdb->update(comments,array( ‘comment_karma’=>’$currentvoteplus’ ),array( ‘comment_ID’=>’$cmtval’,’comment_post_ID’=>’787′), array( ‘%d’,’%d’ ),array( ‘%d’ )) ;

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

The topic ‘$wpdb->update won't write to database’ is closed to new replies.