-5

現在、質問のタイトルにエラーが表示されるという問題が発生しています。ここに私のコードがあります。何が間違っているのか、それを修正する方法を誰かがチェックするのを手伝ってくれますか? どうもありがとう。

次の部分は、「ヘッダー」を含む php ファイルの下部です。

echo'<table>';
            while ($result = mysql_fetch_array($sql, MYSQL_ASSOC)){
                echo '<tr>';
                echo '<td style="width:142px">';
                echo $result['instrument_id'];
                echo '</td>';
                echo '<td style="width:142px">';
                echo $result['instrument'];
                echo '</td>';
                echo '<td style="width:142px">';
                echo $result['type'];
                echo '<br>';
                echo $result['amount'].'&nbsp;shares';
                echo '</td>';
                echo '<td style="width:142px">';
                echo $result['opening_rate'];
                echo '<br>';
                $fp = fopen ("http://finance.yahoo.com/d/quotes.csv?s='".$result['instrument']."'&f=nsb2b3p2ophg.csv","r");
                    //this uses the fgetcsv function to store the quote info in the array $data
                    $data = fgetcsv ($fp, 1000, ",");
                    echo ($data[3]);//current rate
                echo '</td>';
                echo '<td style="width:142px">';
                echo $result['opening_value'];
                echo '<br>';
                $value = $data[3] * $result['amount'];
                $currentvalue = number_format($value, 2, '.', '');
                echo $currentvalue;//current value
                echo '</td>';
                echo '<td style="width:142px">';
                echo $result['open_time'];
                echo '</td>';
                echo '<td style="width:142px">';
                if($data[3] == 0){
                echo '<input type="submit" name="close'.$result['instrument_id'].'" value="Close" disabled="disabled"/>';}
                else{
                echo '<input type="submit" name="close'.$result['instrument_id'].'" value="Close"/>';}
                echo '</td>';
                echo '</tr>';

                fclose ($fp);

                $name = 'close'.$result['instrument_id'];
                $close = isset($_POST[$name]);
                if($close){

                    $instrumentid = $result['instrument_id'];
                    $_SESSION['instrumentid'] = $instrumentid;


                    $instrument = $result['instrument'];
                    $_SESSION['instrument'] = $instrument;

                    $amount = $result['amount'];
                    $_SESSION['amount'] = $amount;

                    header("Location:order_sell.php");
                }   
            }
            echo'</table>'; 

html要素のみを含む背景ファイルであるファイルを一番上に含めると、警告のようなエラーメッセージが表示されます:ヘッダー情報を変更できません...ここに含まれるファイルのコードがあります:

<?php 
session_start();

    // checks if $_SESSION['userid'] exists
    $areYouLoggedIn = isset($_SESSION['username']);
?>
<!DOCTYPE html>
<html>
<head>

<style type="text/css">

/* background*/
body { background: url(images/background2.png) center center fixed no-repeat; 
webkit-background-size:cover;
moz-bacground-size:cover;
-o-background-size:cover;
background-size:cover;}

/* top menu layout*/
.Topmenu{
width:1000px;
background: #00AEEF;
border-radius: 3px 3px 3px 3px;
}

/* top menu cell layout*/
.Tabcells{ width:200px; 
text-align:center;
}

/* top menu cell text layout*/

/* top menu cell text layout*/
.Tabtexteffect
{ text-decoration: none;
color:white;
font-family:Arial;
font-size:15px;
}

.Tabtexteffect:hover
{
text-decoration: none;
color:white;
font-family:Arial;
font-size:20px;
}

.Paragraph {text-align:justify; 
text-justify:distributed-all-lines;
text-align-last:justify; 
font-family:arial; 
font-size:12pt;
width:1000px;
}

.Box {
width:950px;
text-align:left;
background: -webkit-linear-gradient(90deg, #F0E68C, #FFFFE0) repeat scroll 0 0 transparent;
background: -moz-linear-gradient(90deg, #F0E68C, #FFFFE0) repeat scroll 0 0 transparent;
border: 1px solid #AAAAAA;
border-radius: 10px 10px 10px 10px;
box-shadow: 0 0 15px #AAAAAA;
}

.Box2 {
    width: 200px;
    text-align: left;
    background: -webkit-linear-gradient(90deg, #FFFA8C, #FFFFE0) repeat scroll 0 0 transparent;
    background: -moz-linear-gradient(90deg, #FFFA8C, #FFFFE0) repeat scroll 0 0 transparent;
    border: 1px solid #AAAAAA;
    border-radius: 10px 10px 10px 10px;
    box-shadow: 0 0 15px #AAAAAA;
}


.Button {
background: -moz-linear-gradient(90deg, #0459B7, #08ADFF) repeat scroll 0 0 transparent;
background: -webkit-linear-gradient(90deg, #0459B7, #08ADFF) repeat scroll 0 0 transparent;
border: 1px solid #093C75;
border-radius: 3px 3px 3px 3px;
box-shadow: 0 1px 0 #FFFFFF;
color: #FFFFFF;
cursor: pointer;
font-family: Arial,sans-serif;
font-size: 12px;
font-weight: bold;
margin-right: -16px;
margin-top: 16px;
padding: 5px 10px;
text-decoration: none;
text-shadow: 0 1px 1px #333333;
text-transform: uppercase;
}




</style>


</head>
<body>
<form action="HomePage.php" method="POST">
<div style="width:1000px; margin:0 auto; min-height:100%;">
<div>
<a href="HomePage.php"><img style="width:25%;" src="images/Mock Apprentice.png" alt="Mock Apprentice"></img></a>
<?php 
if($areYouLoggedIn==false){
    echo'<table cellpadding="0" align="right" style="position: absolute; left: 940px; top: 15px;">';
    echo'<tr>';
    echo'<td width="130" align="center"><font face="Arial" size="3"><a href="Login.php"><input type="button" class="Button" value="Sign In""/></a></font></td>';
    echo'<td width="1" bgcolor=black><BR></td>';
    echo'<td width="100" align="center"><font face="Arial" size="3"><a href="Registration.php"><input type="button" class="Button" value="Sign Up""/></a></font></td>';
    echo'</tr>';
    echo'</table>';
}
if($areYouLoggedIn == true){
    echo'<table cellpadding="0" align="right" style="position: absolute; left: 950px; top: 40px;">';
    echo'<tr>';
    echo'<td width="130" align="center"><font face="Arial" size="4" color="#00AEFF">Welcome';
    echo'&nbsp';
    echo'<font color="#FFD700">';
    echo($_SESSION['username']);
    echo'</font>';
    echo'</font></td>';
    echo'<td width="1" bgcolor=black><BR></td>';
    echo'<td width="100" align="center"><font face="Arial" size="4"><a style="text-decoration: none; color:#00AEFF;" href="Logout.php">Logout</a></font></td>';
    echo'</tr>';
    echo'<table>';
}
?>
<HR color="#00AEEF">
</div>
<div>
<table width="1020" height="30" class="Topmenu">
<tr>
<td width="200" height="30" class="Tabcells"><a href="Intro.php" class="Tabtexteffect">Intro</a></td>
<td width="200" class="Tabcells"><a href="HowToUse.php" class="Tabtexteffect">How to use</a></td>
<td width="200" class="Tabcells"><a href="Elearning.php" class="Tabtexteffect">Education Center</a></td>
<td width="200" class="Tabcells"><a href="ITQuotes.php" class="Tabtexteffect">Trading Platform</a></td>
<td width="196" class="Tabcells"><a href="ContactUs.php" class="Tabtexteffect">Contact Us</a></td>
</tr>
</table>
</div>
</div>
</form>
</body>
</html>

どうもありがとうございました!

4

5 に答える 5

10

で置き換えheader("Location:order_sell.php");てみてください

echo '<META HTTP-EQUIV="Refresh" Content="0; URL=order_sell.php">';    
exit;
于 2012-09-03T22:28:15.100 に答える
2

出力するものは何でも - HTML のみまたは PHP からの出力: 関数をいじらない限り、ob_*()何かを出力した瞬間にヘッダーを送信できなくなります。

これが、これらが呼び出される理由headersです。HTTP プロトコルでは、<?phpタグの前の空行などの空白を含む、ペイロード本体のすべての部分に先行します。

これに取り組む典型的な方法は、最初に必要なヘッダーを計算するようにロジックを再編成し、次にecho()、などを介して出力を作成することです。printf()include()

于 2012-09-03T22:21:52.360 に答える
0

PHP では、サーバーから出力が送信されるheader前に関数を呼び出す必要があります。これには、ブロックの前の呼び出しと HTML 情報が含まれます。echo<?php ?>

于 2012-09-03T22:19:15.077 に答える
0

headerテキストがブラウザに送信された後に送信することはできません。

header("Location:order_sell.php");

テキスト/出力/空白がブラウザに送信/エコーされる前に必要です。

于 2012-09-03T22:19:25.920 に答える
0

header("Location:someLocation") を使用する場合は、ブラウザーに文字が出力されていないことを確認してください。そうしないと、エラー Cannot modify header information. 詳細はこちら: http://php.net/manual/en/function.header.php

于 2012-09-03T22:22:31.933 に答える