2012-03-28 16 views
-2

を「ヘッダー情報を変更することはできません」私はYouTubeのチュートリアルを追従しながら、この警告を得ている、と理由を把握することはできません。が警告

警告:ヘッダー情報を変更することはできません - すでに(出力が開始により送信されたヘッダを/Applications/XAMPP/xamppfiles/htdocs/storeadmin/inventory_list.php:23

でこれはコードです:

<?php 
session_start(); 
if(!isset($_SESSION["manager"])){ 
header("location: admin_login.php"); 
exit(); 
} 
$managerID = preg_replace('#[^0-9]#i','',$_SESSION["id"]);//filter everything but numbers 
$manager= preg_replace('#[^A-Za-z0-9]#i','',$_SESSION["manager"]); 
$password= preg_replace('#[^A-Za-z0-9]#i','',$_SESSION["password"]); 

include "../connect_to_mysql.php";//includes file to connect to db 
$sql= mysql_query("SELECT * FROM admin WHERE id='$managerID' AND username='$manager' AND password='$password' LIMIT 1"); 

$existCount=mysql_num_rows($sql); //count row 
if ($existCount == 0) { 

echo "your login does not exist"; 
exit(); 
} 
?> 


<?php 
error_reporting(E_ALL);//error report testing 
ini_set('display_errors','1'); 
?> 

<?php 
// Delete Item Question to Admin, and Delete Product if they choose 
if (isset($_GET['deleteid'])) { 
    echo 'Do you really want to delete product with ID of ' . $_GET['deleteid'] . '? <a href="inventory_list.php?yesdelete=' . $_GET['deleteid'] . '">Yes</a> | <a href="inventory_list.php">No</a>'; 
    exit(); 
} 
if (isset($_GET['yesdelete'])) { 
    // remove item from system and delete its picture 
    // delete from database 
    $id_to_delete = $_GET['yesdelete']; 
    $sql = mysql_query("DELETE FROM products WHERE id='$id_to_delete' LIMIT 1") or die (mysql_error()); 
    // unlink the image from server 
    // Remove The Pic ------------------------------------------- 
    $pictodelete = ("../inventory_images/$id_to_delete.jpg"); 
    if (file_exists($pictodelete)) { 
       unlink($pictodelete); 
    } 
    header("location: inventory_list.php"); 
    exit(); 
    } 
?> 


<?php 
//parse form data adds inventory item to database 
if(isset($_POST['product_name'])){ 
$product_name = mysql_real_escape_string($_POST['product_name']); 
$price = mysql_real_escape_string($_POST['price']); 
$proddescription = mysql_real_escape_string($_POST['proddescription']); 
$genre = mysql_real_escape_string($_POST['genre']); 
$quantity = mysql_real_escape_string($_POST['quantity']); 
//this checks if an item already exists under this name 
$sql= mysql_query("SELECT id FROM products WHERE product_name='$product_name' LIMIT 1"); 
$productMatch = mysql_num_rows($sql); 
if($productMatch > 0){ 
echo 'Sorry, this item already exists, <a href="inventory_list.php">click here</a>'; 
exit(); 
} 
//add items to database 
$sql = mysql_query("INSERT INTO products (product_name, price, proddescription, genre, quantity) 
VALUES('$product_name','$price','$proddescription','$genre','$quantity')") or die (mysql_error()); 
$pid = mysql_insert_id(); 

    // Place image in the folder 
    $newname = "$pid.jpg"; 
    move_uploaded_file($_FILES['fileField']['tmp_name'], "../inventory_images/$newname"); 
    header("location: inventory_list.php"); 
    exit(); 
} 
?> 

<?php 
//this displays whole list 
$product_list=""; 
$sql = mysql_query("SELECT * FROM products"); 
$productCount =mysql_num_rows($sql); 
if($productCount>0){ 
while($row = mysql_fetch_array($sql)){ 
$id = $row["id"]; 
$product_name = $row["product_name"]; 
$price = $row["price"]; 
$quantity = $row["quantity"]; 
$product_list.="$id - $product_name - $quantity - $price &nbsp; &nbsp; &nbsp; <a href= 'inventory_edit.php?pid=$id'>edit</a> &bull; <a href='inventory_list.php?deleteid=$id'>delete</a><br />"; 
} 
} else { 
$product_list = "There are no products in the store."; 
} 
?> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr"> 

<head> 
    <title>Inventory List</title> 
    <link href="../style2.css" rel="stylesheet" type="text/css" /> 
</head> 

<body> 

<div id="container"> 

    <div id="masthead"> 
    </div> 

    <div id="navigation"> 
     <p><a href="index1.php">Home</a> 
     <a href="fiction.php">Fiction</a> 
     <a href="travel.php">Travel</a> 
     <a href="sport.php">Sport</a> 
     <a href="arts.php">Arts & Design</a> 
     <a href="cart.php">Shopping Cart</a> 
     <a href="account.php">Manage Account</a></p> 



    </div> 

    <div id="content"> 
    <div align ="right" style="margin-right:32px;"><a href="inventory_list.php#inventoryForm">+ Add New Item</a></div> 
    <div align="left" style="margin-left:24px;"> 
    </div> 

<h4>Inventory List</h4> 
<?php echo $product_list; ?> 

<a name = "inventoryForm" id="inventoryForm"></a> 
<h3> 
&darr; Add New Item Form &darr; 
</h3> 
<form action="inventory_list.php" enctype="multipart/form-data" name="myForm" id="myForm" method="post"> 
<table width="90%" border="0" cellspacing="0" cellpadding="6"> 
<tr> 
<td width="20%">Product Name</td> 
<td width="80%"><label> 
<input name="product_name" type="text" id="product_name" size="64" /> 
</label></td> 
</tr> 
<tr> 
<td>Product Price</td> 
<td><label> 
&pound; 
<input name="price" type="text" id="price" size="12" /> 
</label></td> 
</tr> 
<tr> 
<td>Description</td> 
<td><label> 
<input name="proddescription" type="text" id="proddescription" size="64" /> 
</label></td> 
</tr> 
<tr> 
<td>Genre</td> 
<td><label> 
<select name="genre" id="genre" /> 
<option value=""></option> 
<option value="Fiction">Fiction</option> 
<option value="Travel">Travel</option> 
<option value="Sport">Sport</option> 
<option value="Arts & Design">Arts & Design</option> 
</select> 
</label></td> 
</tr> 
<tr> 
<td>Product Image</td> 
<td><label> 
<input type="file" name="fileField" id="fileField" /> 
</label></td> 
</tr> 
<tr> 
<td>Quantity</td> 
<td><label> 
<input name="quantity" type="text" id="quantity" size="4" /> 
</label></td> 
</tr> 
<tr> 
<tr> 
<td>&nbsp;</td> 
<td><label> 
<input type="submit" name="button" id="button" value="Add Item" /> 
</label></td> 
</tr> 
</table> 
</form> 
<br /> 
<br /> 
</div> 

    <div id="footer"> 
     <p>ADMIN AREA</p> 
    </div> 

</div> 

</body> 

</html> 
+0

私に関連した 'session_start()'を見ます。非常に上になければなりません。他の出力は前もって送信されなければなりません(例えば 'echo'など)。このファイルは 'session_start()'と一緒に必要ですか他の場所に含まれていますか? –

+0

あなたは ''タグの間にギャップがあります。それらは空白としてブラウザに送られます。空白でなくコンテンツが送信された後でも、ヘッダーを送信することはできません。 – JJJ

+2

また、これは文字通り右側のサイドバーにあるすべての関連する質問の複製です。 – JJJ

答えて

0

あなたがPHPタグの外に空行を持って修正するために、すべてのそれらを一緒にマージすることもできます。これは、改行を送信するためにPHPを引き起こします

?> 


<?php 

+0

ありがとうございました、アイテムを削除すると問題が解決しました。しかし、1つ追加すると、まだこの警告が表示されています 警告:ヘッダー情報を変更できません - /Applications/XAMPP/xamppfiles/htdocs/storeadmin/inventory_list.php:68の出力が/ Applications/XAMPPに送信されました。 /xamppfiles/htdocs/storeadmin/inventory_list.php on line 69 – JTH

+0

多くの別々のものではなく、1つの '<?php'ブロックだけがあることを確認してください。まだ問題がある場合は、投稿のコードを更新してください。警告の行番号をヒントとして使用してください。 –

0

エラーはあなたが時間を変更することはできません言うようにeaders。したがって、header()機能を使用している場合は、<?php ?>タグの外側にスペースやコンテンツがないことを確認してください。同じスクリプト内で同じヘッダーを2回送信しないでください。このようないくつかの問題があなたのコードにあります:

... 
echo "your login does not exist"; 
exit(); 
} 
?> 

//here you have space and \n 
<?php 

すべてのPHPブロックをマージします。

0

これは、後のブロックのheader()コールのいずれかで発生しています。例えば、第3 <?php ?>ブロックでそれを呼び出します:

header("location: inventory_list.php"); 

生のHTMLとしてカウントはとすぐそれが外に(最初の行を起こるようにユーザーのブラウザに送信されるように、あなたは、各<?php ?>ブロックの間に空行を持っていますのコードブロックの行23、なぜそれがエラーで言及されている)です。データを送信する前にヘッダーを送信する必要があります。その時点でヘッダーを変更することはできません。あなたのPHPブロックが、空白行との間に何もないので、あなたはそれ

+0

ありがとうございました。これはアイテムを削除するときに解決されますが、アイテムを追加するとこのエラーが発生します... 警告:ヘッダー情報は既に送信されています(出力は/ Applications/XAMPP/xamppfiles/htdocs/storeadmin/inventory_list.php:68)in /Applications/XAMPP/xamppfiles/htdocs/storeadmin/inventory_list.php on line 69 – JTH

+0

あなたはinventory_list.phpの68行目に出力を送信しています。 – JJJ