admin管理员组文章数量:1130349
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
|
1 Answer
Reset to default 3You 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.
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_errorto know if you get any error. – Aniruddha Gawade Commented Aug 22, 2017 at 13:11 -
What is your
$wpdb->prefixvalue ? If it's the defaultwp_then you may start removing this prefix from"wp_list_press". – ClemC Commented Aug 22, 2017 at 13:40
1 Answer
Reset to default 3You 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.
本文标签: wpdbWhy doesn39t my insert query work
版权声明:本文标题:wpdb - Why doesn't my insert query work? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749154836a2324433.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


$wpdb->last_errorto know if you get any error. – Aniruddha Gawade Commented Aug 22, 2017 at 13:11$wpdb->prefixvalue ? If it's the defaultwp_then you may start removing this prefix from"wp_list_press". – ClemC Commented Aug 22, 2017 at 13:40