$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>wpdb - Why doesn't my insert query work?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

wpdb - Why doesn't my insert query work?

matteradmin8PV0评论

I'm trying to insert to the table in my wordpress database but for some reason it's failing all the time.

$table_name = $wpdb->prefix . "wp_list_press";

$res = $wpdb->replace( $table_name, array(
    'pr_id'    => $da, 
    'pr_title' => $t,
    'pr_link'  => $str,
    'pr_date'  => $date,
    'pr_text'  => $tx,
    'pr_desc'  => $desc,
    'pr_image' => $im,
    'pr_pdf'   => $pd,
),
array(
    '%d',
    '%s',
    '%s',
    '%s',
    '%s',
    '%s',
    '%s',
    '%s',
    '%s',
    '%s',
));

if ( $res ) {
    print( "Success" );

} else {
    print( "Failed" );
}

I'm trying to insert to the table in my wordpress database but for some reason it's failing all the time.

$table_name = $wpdb->prefix . "wp_list_press";

$res = $wpdb->replace( $table_name, array(
    'pr_id'    => $da, 
    'pr_title' => $t,
    'pr_link'  => $str,
    'pr_date'  => $date,
    'pr_text'  => $tx,
    'pr_desc'  => $desc,
    'pr_image' => $im,
    'pr_pdf'   => $pd,
),
array(
    '%d',
    '%s',
    '%s',
    '%s',
    '%s',
    '%s',
    '%s',
    '%s',
    '%s',
    '%s',
));

if ( $res ) {
    print( "Success" );

} else {
    print( "Failed" );
}
Share Improve this question edited Aug 22, 2017 at 19:57 ChrisM 1271 silver badge8 bronze badges asked Aug 22, 2017 at 13:02 E.KE.K 132 bronze badges 2
  • Try printing $wpdb->last_error to know if you get any error. – Aniruddha Gawade Commented Aug 22, 2017 at 13:11
  • What is your $wpdb->prefix value ? If it's the default wp_ then you may start removing this prefix from "wp_list_press". – ClemC Commented Aug 22, 2017 at 13:40
Add a comment  | 

1 Answer 1

Reset to default 3

You have the following for the table name: $wpdb->prefix . "wp_list_press"

Check your actual prefix and table name. In a WP installation using "wp_" as the prefix, the above would result in "wp_wp_list_press". Is that the table name in the db or is it just "wp_list_press"?

If the table in the db is "wp_list_press" then the above should be $wpdb->prefix . "list_press";

Not sure if this is contributing to the issue or not, but your data array has fewer elements than your format array.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far