我从2016年底开始测试一些代码,发现$wpdb->insert()不再有效。Maybe something todo with php7? 我不知道。
之前,以下代码工作正常。$\\u POST()中的数据填写正确。
if(isset($_POST[\'add_new_banner\'])){
extract($_POST); // correct data
$wpdb->insert(
$wpdb->prefix.\'rdp_banners\',
array(
\'banner_id\' => $banner_id,
\'rdp_banner\' => $rdp_banner,
\'banner_type\' => $banner_type,
\'customer_id\' => $customer_id,
\'status\' => $status,
\'company_name\' => $company_name,
\'picture\' => $picture,
\'register_date\' => $register_date,
\'start_date\' => $start_date,
\'end_date\' => $end_date,
\'price\' => $price,
\'banner_link\' => $banner_link,
),
array( \'%d\', \'%d\', \'%d\', \'%d\', \'%d\', \'%s\', \'%s\', \'%s\',\'%s\', \'%s\', \'%s\', \'%s\',)
);
我是否需要在某个地方更改代码以使其正常工作?希望有人能告诉我我做错了什么。
最合适的回答,由SO网友:DHL17 整理而成
检查以下示例并找出代码的错误。
global $wpdb;
if(isset($_POST[\'submit\']))
{
$table_name = $wpdb->prefix.\'employee\';
$wpdb->insert(
$table_name,
array(
\'first_name\'=>$fname,
\'last_name\'=>$lname),
array( \'%s\',\'%s\' )
);
使用
global $wpdb;
global $wpdb;
$table_name = $wpdb->prefix.\'rdp_banners\';
$wpdb->insert(
$table_name,
array(
\'banner_id\' => $banner_id,
\'rdp_banner\' => $rdp_banner,
\'banner_type\' => $banner_type,
\'customer_id\' => $customer_id,
\'status\' => $status,
\'company_name\' => $company_name,
\'picture\' => $picture,
\'register_date\' => $register_date,
\'start_date\' => $start_date,
\'end_date\' => $end_date,
\'price\' => $price,
\'banner_link\' => $banner_link),
array( \'%d\', \'%d\', \'%d\', \'%d\', \'%d\', \'%s\', \'%s\', \'%s\', \'%s\', \'%s\', \'%s\', \'%s\')
);