【发布时间】:2012-11-17 04:02:34
【问题描述】:
我正在尝试使用 insert.php 作为操作从表单发布数据。但是,一旦数据发布到数据库,我就无法重定向回 index.php。
我搜索了以下网站以找到答案:
以及关于该主题的十个 stackoverflow 问题。
下面是 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
【问题讨论】:
-
标题应该在任何输出之前。
-
确保您的文件顶部没有空行或空格,或者您需要()或包含()的任何其他文件