您好我搜索了解决方案,但我无法修复它-_-
我有一个表单,当我点击提交时显示此错误
警告:无法修改标题信息 - 已在第68行的C:\ xampp \ htdocs \ new1v2 \ alumnireg.php中发送的标题(输出从C:\ xampp \ htdocs \ new1v2 \ topnav.php:72开始)< / p>
这是我的php代码的一部分
if (mysqli_query($conn, $sql) === TRUE) {
echo
header('location:thanks.php');
如果我点击提交,应该转到thanks.php 但如果我删除我的topnav.php它运作良好
我的topnav.php有什么问题?
<!-- active class in navigation -->
<style>
.active {
background-color:#2980b9;
}
</style>
<!-- end of active -->
<style>
.nav li a:hover{
background-color: #0452BC;
/*font-size:18px;*/
}
</style>
<script>
// Change style of top container on scroll
window.onscroll = function() {scrollFunc()};
function scrollFunc() {
if (document.body.scrollTop > 200 || document.documentElement.scrollTop > 200) {
document.getElementById("myTop").classList.add("w3-blue","w3-card-4");
document.getElementById("myIntro").classList.add("w3-show-inline-block");
} else {
document.getElementById("myIntro").classList.remove("w3-show-inline-block");
document.getElementById("myTop").classList.remove("w3-blue","w3-card-4");
}
}
</script>
<!-- for top nav to be not overlapped by the indicators of carousel -->
<style>
.w3-card-4.w3-blue{z-index: 99999;}
</style>
<!-- end of style for top nav to be not overlapped -->
<div id="myTop" class="w3-top w3-container w3-padding-2 w3-theme w3-large">
<!-- <i class="w3-opennav w3-hide-large w3-xlarge w3-margin-left w3-margin-right" onclick="w3_open()"></i> -->
<div id="myIntro" class="w3-hide">
<a href="index.php">
<img src="admin/img/fcuautonomous.png" width="200px" height="50" style="padding:5px;">
</a>
</div>
</div>
<header class="w3-container w3-theme w3-padding-18 w3-blue" style="background-image: url(admin/img/top.jpg); background-size: 100% 100%;">
<h1 class="w3-xxxlarge w3-padding-16">
<a href="index.php">
<img src="admin/img/fcuautonomous.png" width="400px">
</a>
</h1>
</header>
<nav class="w3-card-4" style="background-color: #013275;">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<i class="fa fa-chevron-circle-down" aria-hidden="true"></i>
</button>
<!-- <a class="navbar-brand" href="index.php"><b><img src="admin/img/fculogo.png" height="35" width="35"></b></a> -->
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right">
<li><a id='homie' href="index.php"><font color="white">Home</font></a></li>
<li><a href="alumnireg.php"><font color="white">Alumni Registration</font></a></li>
<li><a href="news_events.php"><font color="white">Events</font></a></li>
<!-- <li><a href="job_opp.php"><font color="white">Job Oppurtunities</font></a></li> -->
<li><a href="featured_alum.php"><font color="white">Featured Alumni</font></a></li>
<li><a href="#contact"><font color="white">Photo Gallery</font></a></li>
</ul>
</div>
</div>
</nav>
<br><br>
请帮助,这是我的THESIS
答案 0 :(得分:2)
你可以使用缓冲。
尝试以下方法:
ob_start(); // <-- put this at the very top of the script, after opening PHP tags.
if (mysqli_query($conn, $sql) === TRUE) {
header('location:thanks.php');
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
ob_end_flush();
//flush();
//exit(0);
如果您因任何其他原因需要避免错误,请使用以下行:
if (mysqli_query($conn, $sql) === TRUE && headers_sent() === false) {...
来源:
答案 1 :(得分:1)
基本问题是你回复了一些输出(样式标签,脚本标签等),然后尝试设置和发送标头。 因此,您可以在topnav.php的include的顶部移动逻辑,或者使用其他选项解决它。
缓冲(ob_start / end)捕获输出,只有在调用ob_end_flush后才会回显(刷新)。
另一种选择就是将{if}块移到include(topnav.php)
答案 2 :(得分:1)