PHP警告:无法修改标题信息,需要解决错误
我是新来的WhitPHP,我正在尝试制作一个web应用程序,在那里我可以创建销售项目并修改它们ECC ECC。这是一种仓库管理软件 下面的代码是用于插入新销售项目的表单 第二个代码是my form中的代码调用的函数,用于在数据库中插入sales items数据 我的代码有一个错误,但我不明白 这是我的页面表单:PHP警告:无法修改标题信息,需要解决错误,php,header,output,warnings,Php,Header,Output,Warnings,我是新来的WhitPHP,我正在尝试制作一个web应用程序,在那里我可以创建销售项目并修改它们ECC ECC。这是一种仓库管理软件 下面的代码是用于插入新销售项目的表单 第二个代码是my form中的代码调用的函数,用于在数据库中插入sales items数据 我的代码有一个错误,但我不明白 这是我的页面表单: <?php require('includes\dbconn.php'); require('includes\dbfunction.php'); session_start();
<?php
require('includes\dbconn.php');
require('includes\dbfunction.php');
session_start();
if(isset($_SESSION["username"])){
?>
<!DOCTYPE html>
<html>
<title>W3.CSS Template</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
<style>
html,body,h1,h2,h3,h4,h5 {font-family: "Raleway", sans-serif}
</style>
<body class="w3-light-grey">
<!-- Top container -->
<div class="w3-bar w3-top w3-black w3-large" style="z-index:4">
<button class="w3-bar-item w3-button w3-hide-large w3-hover-none w3-hover-text-light-grey" onclick="w3_open();"><i class="fa fa-bars"></i> Menu</button>
<span class="w3-bar-item w3-right">BK2 Gestionale</span>
</div>
<!-- Sidebar/menu -->
<nav class="w3-sidebar w3-collapse w3-white" style="z-index:3;width:300px;" id="mySidebar"><br>
<div class="w3-container w3-row">
<div class="w3-col s12 w3-bar w3-center">
<?php
if(isset($_SESSION["username"])){
echo "<p>Benvenuto " . $_SESSION["username"] . "</p>";
?>
<a href="#" class="w3-bar-item w3-button"><i class="fa fa-user"></i></a>
<a href="impostazioni.php" class="w3-bar-item w3-button"><i class="fa fa-cog"></i></a>
<a href="logout.php" class="w3-bar-item w3-button"><i class="fas fa-sign-in-alt"></i></a>
<?php
}
else{
header( "refresh:3;url=index.php" );
}
?>
</div>
</div>
<hr>
<div class="w3-container">
<h5>Dashboard</h5>
</div>
<div class="w3-bar-block">
<a href="#" class="w3-bar-item w3-button w3-padding-16 w3-hide-large w3-dark-grey w3-hover-black" onclick="w3_close()" title="close menu"><i class="fa fa-remove fa-fw"></i> Close Menu</a>
<a href="index.php" class="w3-bar-item w3-button w3-padding"><i class="fas fa-home"></i> Home</a>
<?php
if(isset($_SESSION["username"])){
?>
<a href="statistiche.php" class="w3-bar-item w3-button w3-padding"><i class="fas fa-chart-area"></i> Statistiche</a>
<a href="magazzino.php" class="w3-bar-item w3-button w3-padding w3-blue"><i class="fas fa-warehouse"></i> Magazzino</a>
<a href="contabilita.php" class="w3-bar-item w3-button w3-padding"><i class="fas fa-file-invoice-dollar"></i> Contabilità</a>
<a href="fornitori.php" class="w3-bar-item w3-button w3-padding"><i class="fas fa-parachute-box"></i> Fornitori</a>
<a href="clienti.php" class="w3-bar-item w3-button w3-padding"><i class="fas fa-users"></i> Clienti</a>
<a href="dipendenti.php" class="w3-bar-item w3-button w3-padding"><i class="fas fa-people-carry"></i> Dipendenti</a>
<a href="storico.php" class="w3-bar-item w3-button w3-padding"><i class="fas fa-history"></i> Storico</a>
<a href="impostazioni.php" class="w3-bar-item w3-button w3-padding"><i class="fa fa-cog fa-fw"></i> Impostazioni</a><br><br>
<?php
}
else{
}
?>
</div>
</nav>
<!-- Overlay effect when opening sidebar on small screens -->
<div class="w3-overlay w3-hide-large w3-animate-opacity" onclick="w3_close()" style="cursor:pointer" title="close side menu" id="myOverlay"></div>
<!-- !PAGE CONTENT! -->
<div class="w3-main" style="margin-left:300px;margin-top:43px;">
<div class="w3-container">
<div class="w3-row">
<div class="w3-col s12 l3">
<br>
</div>
<div class="w3-col s12 l5">
<form class="w3-container" action="nuovoarticolo.php" method="post">
<label class="w3-text-blue"><b>Descrizione articolo:</b></label>
<input class="w3-input w3-border" name="nomearticolo" type="text" required><br>
<label class="w3-text-blue"><b>Codice articolo:</b></label>
<input class="w3-input w3-border" name="codicearticolo" type="text" required><br>
<label class="w3-text-blue"><b>Barcode:</b></label>
<input class="w3-input w3-border" name="barcode" type="text" required><br>
<label class="w3-text-blue"><b>Prezzo acquisto:</b></label>
<input class="w3-input w3-border" name="prezzoAcquisto" type="text" required><br>
<label class="w3-text-blue"><b>Prezzo vendita:</b></label>
<input class="w3-input w3-border" name="prezzoVendita" type="text" required><br>
<label class="w3-text-blue"><b>Quantità:</b></label>
<input class="w3-input w3-border" name="quantita" type="text" required><br>
<label class="w3-text-blue"><b>Sconto %:</b></label>
<input class="w3-input w3-border" name="scontoPercentuale" type="text" required><br>
<button class="w3-btn w3-blue" type="submit">CREA ARTICOLO</button>
</form>
<?php
if(isset($_POST["nomearticolo"]) && isset($_POST["codicearticolo"]) && isset($_POST["barcode"])
&& isset($_POST["prezzoAcquisto"]) && isset($_POST["prezzoVendita"]) && isset($_POST["quantita"])
&& isset($_POST["scontoPercentuale"])){
$nomeArticolo = $_POST["nomearticolo"];
$codiceArticolo = $_POST["codicearticolo"];
$barcodeArticolo = $_POST["barcode"];
$prezzoAcquistoArticolo = $_POST["prezzoAcquisto"];
$prezzoVenditaArticolo = $_POST["prezzoVendita"];
$quantitaArticolo = $_POST["quantita"];
$scontoPercentualeArticolo = $_POST["scontoPercentuale"];
creaNuovoArticolo($nomeArticolo, $codiceArticolo, $barcodeArticolo, $prezzoAcquistoArticolo, $prezzoVenditaArticolo, $quantitaArticolo, $scontoPercentualeArticolo);
}
?>
</div>
<div class="w3-col s12 l3">
<br>
</div>
</div>
</div>
</div>
<script>
// Get the Sidebar
var mySidebar = document.getElementById("mySidebar");
// Get the DIV with overlay effect
var overlayBg = document.getElementById("myOverlay");
// Toggle between showing and hiding the sidebar, and add overlay effect
function w3_open() {
if (mySidebar.style.display === 'block') {
mySidebar.style.display = 'none';
overlayBg.style.display = "none";
} else {
mySidebar.style.display = 'block';
overlayBg.style.display = "block";
}
}
// Close the sidebar with the close button
function w3_close() {
mySidebar.style.display = "none";
overlayBg.style.display = "none";
}
</script>
</body>
</html>
<?php
}
else{
header("location: accessonegato.php");
}
?>
我不明白如何解决这个问题。
如果有人能检查我的代码,并告诉我我的错误,我很感激
对不起,我的英语不好 你的问题与我们的关系密切 在调用
header()
之前出现任何输出时,就会发生错误
该输出可以是HTML标记或PHP的其他输出,甚至可以是PHP文件开头的空白或代码编辑器添加的字节顺序标记
您需要将所有与头相关的逻辑移到代码的开头,或者使用PHP输出缓冲-请参阅缓冲讨论。请不要通过将字符串连接在一起来创建SQL查询。您应该始终使用参数化查询,否则SQL注入会给您带来严重的安全风险。如果您发送了两次标头,则错误很明显。首先当您使用dbfunction.php时,然后在您的nuovoarticolo.php中发送头('Location:articolocreato.php');将html行发送到客户端服务器后。发表评论,它就会起作用。在其他地方进行重新定位。为了帮助实现这一点,我们确实需要知道文件dbFunction.php的第42行在哪里。我猜是这一行的标题(“refresh:3;url=index.php”);`。mydbfunction.php中的第42行是:header('Location:articolocreato.php');
function creaNuovoArticolo($nomeArticolo, $codiceArticolo, $barcodeArticolo, $prezzoAcquistoArticolo, $prezzoVenditaArticolo, $quantitaArticolo, $scontoPercentualeArticolo){
require('dbconn.php');
$sql = "INSERT INTO articoli (nomeArticolo, codiceArticolo, barcode, prezzoAcquisto, prezzoVendita, quantita, scontoPercentuale) VALUES('$nomeArticolo', '$codiceArticolo', '$barcodeArticolo', '$prezzoAcquistoArticolo', '$prezzoVenditaArticolo', '$quantitaArticolo', '$scontoPercentualeArticolo')";
if ($conn->query($sql) === TRUE) {
header('Location: articolocreato.php');
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\bk2\nuovoarticolo.php:69) in C:\xampp\htdocs\bk2\includes\dbfunction.php on line 42