我想讓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;
?
好的,我在表單中犯了一個錯誤!我忘了添加'name'的值,以便我的PHP可以接受它! – lukeseager 2013-04-08 17:02:11