运行我的脚本时,我收到几个这样的错误:
警告:不能更改头信息-头已经发出(输出开始/some/file.php:12)在/some/file.php上线23
错误消息中提到的行包含header()和setcookie()调用.
这可能是什么原因?以及如何解决它?
include('header.php');
$name = $_POST['name'];
$score = $_POST['score'];
$dept = $_POST['dept'];
$MyDB->prep("INSERT INTO demo (`id`,`name`,`score`,`dept`, `date`) VALUES ('','$name','$score','$dept','$date')");
// Bind a value to our :id hook
// Produces: SELECT * FROM demo_table WHERE id = '23'
$MyDB->bind(':date', $date);
// Run the query
$MyDB->run();
header('Location:index.php');
exit;
Run Code Online (Sandbox Code Playgroud)
上面的代码一直给我一个重定向问题.错误如下:
警告:无法修改标头信息 - 已在/ Applications/MAMP/htdocs/testygubbins/OO/test/form中发送的标头(在/Applications/MAMP/htdocs/testygubbins/OO/test/header.php:15处开始输出). php在第16行.
我完全被这个弄得晕头转向.有谁知道我应该做些什么来使它工作?
编辑
header.php代码:
<?php
include('class.user.php');
include('class.Connection.php');
$date = date('Y-m-j');
?>
<html>
<head>
<link rel=StyleSheet href="css/style.css" type="text/css" media=screen>
<title>Test</title>
</head>
<body>
<div id="page">
Run Code Online (Sandbox Code Playgroud)