WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] database insert problem (3 posts)

  1. Mihail Semjonov
    Member
    Posted 2 years ago #

    Hello,

    I have created new DB table. There's 3 colls, id (auto incriment), name, metabox. Both name and metabox are varchar(255).
    Trying to fill it with rows, but metabox coll always shows 0 (ziro).

    Checked colls name in function that inserts rows, metabox is writen correctly. the function recives the value which must be inserted in metabox coll (chacked also).

    Don't know what might go wrong.
    Help plese!
    Here's the code I have:

    Table creation

    $sql = "CREATE TABLE $pages (
        id mediumint(9) NOT NULL AUTO_INCREMENT,
        name varchar(255) NOT NULL,
        metabox varchar(255) NOT NULL,
        UNIQUE KEY id (id,name)
        );";

    inserting row

    global $wpdb;
        $postTypeName = $_POST['name'];
        $metaname = $_POST['metaname'];
        if($wpdb->insert( 'wp_ewtc_pages',array('name' => $postTypeName,'metabox' => $metaname),array('%s','%d'))) {
            die('done');
        } else {
            die('problem');
        }

    Working on localhost (on my PC, using Open Server on Windows 7 x64)
    Wordpress version 3.4.1

  2. Chandan Kumar
    Member
    Posted 2 years ago #

    I have made %d to %s and here is the code:

    $wpdb->insert( 'wp_ewtc_pages',array('name' => $postTypeName,'metabox' => $metaname),array('%s','%s'))

    Note: %d denotes digit/numeric value and you have assigned metabox varchar.

  3. Mihail Semjonov
    Member
    Posted 2 years ago #

    thanks a lot!!

Topic Closed

This topic has been closed to new replies.

About this Topic