如何将以下内容插入到我的定制表中?

时间:2018-04-06 作者:Ragnaboy

$service = array(
\'show_option_all\'    => \'Select your Service\',
\'show_option_none\'   => \'\',
\'option_none_value\'  => \'-1\',
\'orderby\'            => \'name\',
\'order\'              => \'ASC\',
\'show_count\'         => 0,
\'hide_empty\'         => 1,
\'child_of\'           => 0,
\'exclude\'            => \'\',
\'include\'            => \'\',
\'echo\'               => 1,
\'selected\'           => \'\',
\'hierarchical\'       => 0,
\'name\'               => \'reliable-cat\',
\'id\'                 => \'\',
\'class\'              => \'postform\',
\'depth\'              => 0,
\'tab_index\'          => 1,
\'taxonomy\'           => \'category\',
\'hide_if_empty\'      => false,
\'value_field\'        => \'name\',
);
$area = array(
\'show_option_all\'    => \'Select your Area\',
\'show_option_none\'   => \'\',
\'option_none_value\'  => \'-1\',
\'orderby\'            => \'name\',
\'order\'              => \'ASC\',
\'show_count\'         => 0,
\'hide_empty\'         => 1,
\'child_of\'           => 0,
\'exclude\'            => \'\',
\'include\'            => \'\',
\'echo\'               => 1,
\'selected\'           => \'\',
\'hierarchical\'       => 0,
\'name\'               => \'reliable-tag\',
\'id\'                 => \'\',
\'class\'              => \'postform\',
\'depth\'              => 0,
\'tab_index\'          => 2,
\'taxonomy\'           => \'post_tag\',
\'hide_if_empty\'      => false,
\'value_field\'        => \'name\',
);

if(isset($_POST[\'reliable-search-submit-button\'])){
    global $wpdb;
    $table = $wpdb->prefix . "custom_search_tracker";
    $data = array(
        \'cst_service\' => esc_attr($_POST[\'search-service\']),
        \'cst_area\' => esc_attr($_POST[\'search-area\']),
        );
    $subscribe = $wpdb -> insert($table, $data);
}
插入数据的代码。

<form name="reliable-search-form" id="reliable-search-form" method="POST" action="<?php bloginfo(\'url\');?>/search-results/">
<div id="reliable-service"><input type="text" id="search-service" name="search-service" value="<?php wp_dropdown_categories($service); ?>" /></div><!-- #reliable-service -->
<div id="reliable-area"><input type="text" id="search-area" name="search-area" value="<?php wp_dropdown_categories($area); ?>" /></div><!-- #reliable-area -->
<div id="reliable-search-submit-form"><input type="submit" id="reliable-search-submit-button" name="reliable-search-submit-button" value="Search" /></div><!-- #reliable-submit-form -->
</form>
没有任何内容插入到表中。我已经将此代码用于订阅列表,它可以工作,所以我想知道为什么它在这里不工作。

1 个回复
SO网友:Ragnaboy

它不起作用的原因是因为我的表单操作。我移动了代码,将数据插入到搜索结果页,并按照需要将数据添加到表中。

结束

相关推荐