• Resolved aseliot

    (@aseliot)


    I get a syntax error on the insert query but I have no idea why.

    The reason why I am trying to make a new table it a long story but there is no other way to solve my problem.

    I’ve been at this for a while and the moment I enable the wpdb line it throws an error. But I think that the line is probably not the problem.

    global $wpdb;
        $charset_collate = $wpdb->get_charset_collate();
        $table_name = "vuora_mu_blog_id";
    
        $sql = "CREATE TABLE IF NOT EXISTS $table_name (
              id mediumint(9) NOT NULL AUTO_INCREMENT,
              blogname VARCHAR(50) NOT NULL,
              blogid mediumint(9),
              UNIQUE KEY id (id)
            ) $charset_collate;";
    
        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
        dbDelta( $sql );
    
        $site_details = get_blog_details();
        $my_blogname = $site_details->blog_id;
        $my_blogid = $site_details->blogname;
    
        $wpdb->insert($table_name, array('blogname'=>$my_blogname, 'blogid'=>$my_blogid);
Viewing 3 replies - 1 through 3 (of 3 total)
  • What is the actual error message that you’re seeing?

    Thread Starter aseliot

    (@aseliot)

    I have an index file for a plugin the moment this is loaded I want to create a new table and insert some data.

    The error i got was a syntax error on the last line where I am trying to insert data into the table I just made. Making the table works fine but the insertion does not.

    To test I just copied the code from this (https://codex.wordpress.org/Creating_Tables_with_Plugins) example into the page, but I as of now I can also not get the insertion working. The table is made but the data is not inserted for whatever reason (no error/notice and debugging is on).

    Thread Starter aseliot

    (@aseliot)

    Woops i forgot a ) at the end of the line 🙁

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

The topic ‘wpdb syntax error?’ is closed to new replies.