我試圖從insert.php作爲動作表單POST數據。但是,一旦數據發佈到數據庫,我就不能重定向到index.php。PHP header()函數將不會重定向
我已經通過以下網站搜索中找到了答案:
以及關於這個問題的10點計算器的問題。
下面是insert.php文件的代碼:
<?php
include 'connect.php';
$id = $_POST['id'];
$idea = mysql_real_escape_string($_POST['new_idea']);
if(!$_POST['submit']) {
echo "Please fill out the form!";
header('Location: index.php');
} else {
mysql_query("INSERT INTO user_idea (`id`, `idea`, `time_created`) VALUES(NULL, '$idea', NULL)") or die(mysql_error());
echo "Idea has been added!";
header('Location: index.php');
}?>
從我收集的,如果有文字輸出前的header()函數將不會執行。我已經試過這個功能,沒有回聲「已添加想法!」;並回顯「請填寫表格!」,但我仍然沒有得到重定向。
在此先感謝您的建議。
-MF
頭應該是任何輸出之前。 –
確保你沒有喜歡你的文件的頂部空白行或空的空間,或者您需要()或include() – akatakritos