2013-04-08 35 views
0

我想讓HTML表單將輸入值發佈到WordPress數據庫中的自定義表中。我設法讓一些東西出現在新的行中,但幾乎所有的值都返回N;而不是表單中的值。將HTML表單發佈到新的wp數據庫表

下面是我在我的頁面模板代碼:

<?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 custom tables plugin來製作新表格。品牌,網址和扇區只使用text定義,而關鍵字使用enum('0','1')

任何人有任何想法,爲什麼值不返回,我只是得到N;

+0

好的,我在表單中犯了一個錯誤!我忘了添加'name'的值,以便我的PHP可以接受它! – lukeseager 2013-04-08 17:02:11

回答

0

找出主要問題。我錯過了表單本身的name屬性,所以我的PHP沒有拿起字段值!

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(); ?> 
相關問題