我想建立一個wordpress插件,從我的窗體獲取信息,並將其放入muy數據庫中。這工作得很好,但每當我嘗試將頁面重定向到頁面,您可以編輯項目我得到一個錯誤,標題已發送。我嘗試了一切,從放置get_header();在重定向下嘗試使用鉤子工作,但沒有任何工作。我必須在這裏失去一些東西。wp_redirect給頭已發送錯誤
<?php
global $wpdb;
$path='admin.php?page=my_pirazzo_locations';
$path2='admin.php?page=my_pirazzo_items';
$url=admin_url($path);
$url2=admin_url($path2);
//global $wpdb;
$userdb = $wpdb->prefix. 'users';
$getdata = $wpdb->get_results("SELECT * FROM $userdb");
//if (isset($_GET['id']))
//{
// $id= $_GET['id'];
// echo $id;
//}
//echo $userdb;
if (isset($_POST["submit"]) && $_POST["client"] != "" && $_POST["startdate"] != "" && $_POST["enddate"] != "") {
global $wpdb;
$userdb = $wpdb->prefix . 'users';
$table = $wpdb->prefix . "b2bdomain";
$user_id = strip_tags($_POST["client"]);
$startdate = strip_tags($_POST["startdate"]);
$enddate = strip_tags($_POST["enddate"]);
$isActive = 0;
if ($startdate < $enddate) {
$isActive = 1;
}
$query = $wpdb->get_results("SELECT user_login FROM $userdb WHERE ID = $user_id");
$name = $query[0]->user_login;
$wpdb->insert(
$table,
array(
'userid' => $user_id,
'isActivated' => $isActive,
'name' => $name,
'start_time' => $startdate,
'end_time' => $enddate,
)
);
$url = 'admin.php?page=my_pirazzo_edit';
ob_clean();
ob_start();
wp_redirect($url);
};
?>
<!-- This file should primarily consist of HTML with a little bit of PHP. -->
<div class="wrap">
<h1>beheer zone</h1>
<div class="postbox">
<div class="meta-th">
<h2>nieuwe zone toevoegen</h2>
</div>
<div class="meta-td">
<form method="post" name="cleanup_options" action="">
<fieldset>
<label for="client">Selecteer een Klant</label>
<select name="client" id="client">
<?php foreach($getdata as $data){ ?>
<option value="<?php echo $data->ID ?>"><?php echo $data->user_login ?></option>
<?php } ?>
</select>
</fieldset>
<fieldset>
<label for="startdate">Startdatum</label>
<input type="date" name="startdate" >
<label for="enddate">Einddatum</label>
<input type="date" name="enddate" >
</fieldset>
<?php submit_button('bewaar de zone', 'primary','submit', TRUE); ?>
</form>
</div>
</div>
<hr>
<div class="postbox">
<h2>voeg locatie's toe</h2>
<a href="<?php echo $url ?>"><button class="button-primary">voeg een locatie toe</button></a>
</div>
<hr>
<div class="postbox">
<h2>voeg Producten toe</h2>
<a href="<?php echo $url2 ?>"><button class="button-primary">voeg een locatie toe</button></a>
</div>
你需要做些什麼才能使這段代碼起作用,你需要刪除什麼?這將讓人深入瞭解是什麼導致了這個問題... – mattfryercom
wp_redirect($ url);在這之後把exit();或wp_die(); –
^聽起來很可能,總是在重定向後退出 – mattfryercom