0

我正在尝试使 HTML 表单将输入值发布到 WordPress 数据库中的自定义表中。我设法让一些东西出现在新行中,但几乎我所有的值都返回N;而不是表单中的值。

这是我的页面模板中的代码:

<?php
global $wpdb;
global $current_user;

$userID = $current_user->ID;
$brand = serialize($_POST["brand"]);
$url = serialize($_POST["url"]);
$sector = serialize($_POST["sector"]);
$keywords = serialize($_POST["keywords"]);
if ( 
'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'updateSearch' ) {
        $ufDataUpdate = $wpdb->insert( 'wp_wct3', array( 
        'date' => current_time('mysql'),
        'userid' => $userID,
        'brand' => $brand,
        'url' => $url, 
        'sector' => $sector,
        'keywords' => $keywords ) );
        }
       ?>

<form method="post">


<label for="brand">Brand/Product Name: </label>
    <input type="text" id="brand" placeholder="eg: Spidr" class="clearfix" required />
    <label for="website">Website address: </label>
    <input type="url" id="url" placeholder="eg: www.spidr.co.uk" class="clearfix" required />
    <label for="sector">Market sector: </label>
    <input type="text" id="sector" placeholder="eg: Internet Marketing Tools" class="clearfix" required />
    <label for="keyword">Keywords/Phrases:<br><span class="orange">(comma separated)</span></label>
    <textarea cols="0" rows="8" class="light" id="keywords" required></textarea>


    <input type="submit" id="submit" name="submit" class="button-65 mobile-button" value="release the spiders!">
    <?php wp_nonce_field( 'updateSearch' ); ?>
    <input name="action" type="hidden" id="action" value="updateSearch" />

</form> 

数据库名称在哪里wp_wct3,数组中的每一项都是该表中每一列的名称。

我不确定我的问题是出在这段代码上,还是出在数据库本身的设置上。我使用了Wordpress 自定义表格插件来制作新表格。品牌、网址和部门仅使用text定义,而关键字使用enum('0','1').

任何人都知道为什么这些值没有返回而我只是得到了N;

4

2 回答 2

0

弄清楚了主要问题。我错过了name表单本身的属性,所以我的 PHP 没有获取字段值!

于 2013-04-08T17:12:53.973 回答
0
this is my custom-form template.. it works for me

<?php
/**
Template Name: Custom-Form
 * The template for displaying all pages.
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site will use a
 * different template.
 *
 * @package WordPress
 * @subpackage Twenty_Twelve
 * @since Twenty Twelve 1.0
 */

get_header(); ?>

    <div id="primary" class="site-content">
        <div id="content" role="main">

        <?php
        if (!empty($_POST)) {
        global $wpdb;
            $table = wp_achord;
            $data = array(
                'name' => $_POST['yourname'],
                'chord'    => $_POST['chord']
            );
            $format = array(
                '%s',
                '%s'
            );
            $success=$wpdb->insert( $table, $data, $format );
            if($success){
            echo 'data has been save' ; 
}
}
else   {
?>
        <form method="post">
        <input type="text" name="yourname">
        <textarea name="chord"></textarea>
        <input type="submit">
        </form>

       <?php }  ?>

        </div><!-- #content -->
    </div><!-- #primary -->

<?php get_footer(); ?>
于 2013-07-30T17:09:36.850 回答