$wpdb->insert() is giving error undefined function

后端 未结 3 427
-上瘾入骨i
-上瘾入骨i 2021-01-15 14:51

I have created a new file inside wp-content/theme/mytheme folder.

Inside the file I have written simple query

global $wpdb;
    $insert= $wpdb->i         


        
3条回答
  •  余生分开走
    2021-01-15 15:35

    By these ways , You can do it easily,

    First define $wpdb globally as like global $wpdb;

    require_once('../wp-load.php'); // relative path
    
    insert("wp_submitted_form", array(
       "col_nmae" => $value,
     ));
    ?>
    

    Second Way is

    $sql = $wpdb->prepare(
        "INSERT INTO `wp_submitted_form`    
           (col_nmae) 
     values ($val)");
    $wpdb->query($sql);
    

    Third is

    $sql = "INSERT INTO `wp_submitted_form`
              (col_nmae) 
       values ($val)";
    
    $wpdb->query($sql);
    

    If you are beginner then read more here https://codex.wordpress.org/Class_Reference/wpdb

提交回复
热议问题