运行php脚本时头文件已经发送错误

时间:2016-03-04 06:29:54

标签: php

我遇到了问题。我已经找到了解决方案但没有任何改变。

警告消息仍然显示:

  

信息 - 已经发送的标题(输出开始于   C:\ xampp \ htdocs \ PRFFWC \ edit.php:82)在C:\ xampp \ htdocs \ PRFFWC \ edit.php中   在线199

这是我收到此警告的行:

<input type="text" name="palali"  value=<?php echo $row['palali']; ?>>
header('Location:index.php');}

任何人都可以帮我解决这个问题吗?

我的代码

<?php
include ('db.php');
include ('header.php');
$ID=$_GET['id'];
?>
   <html>

   <body>


      <div class="container">
         <div class="hero-unit-header">
            <div class="container-con">
               <!-- end banner & menunav -->

               <div class="container">
                  <div class="row-fluid">
                     <div class="span12">
                        <div class="row-fluid">
                           <div class="span3"></div>
                           <div class="span6">


                              <div class="hero-unit-3">
                                 <center>
                                    <?php
  $sql= "select * from rainfallstations_copy where id='$ID'" ;
  $result   = mysqli_query($con,$sql) or die('Error: ' . mysqli_error($con));
$row=mysqli_fetch_array($result);
?>
                                       <form class="form-horizontal" method="post" enctype="multipart/form-data" style="float: right;">
                                          <legend>
                                             <h4>Edit</h4></legend>



                                          <h4>PRFFWC Records</h4>
                                          <hr>
                                          <div class="control-group">
                                             <label class="control-label" for="inputmunoz">Munoz:</label>
                                             <div class="controls">
                                                <input type="text" name="munoz" value=<?php echo $row[ 'munoz']; ?>>
                                             </div>
                                          </div>
                                          <div class="control-group">
                                             <label class="control-label" for="inputsapang_buho">Sapang Buho:</label>
                                             <div class="controls">
                                                <input type="text" name="sapang_buho" value=<?php echo $row[ 'sapang_buho']; ?>>
                                             </div>
                                          </div>
                                          <div class="control-group">
                                             <label class="control-label" for="inputgabaldon">Gabaldon:</label>
                                             <div class="controls">
                                                <input type="text" name="gabaldon" value=<?php echo $row[ 'gabaldon']; ?>>
                                             </div>
                                          </div>
                                          <div class="control-group">
                                             <label class="control-label" for="inputzaragoza">Zaragoza:</label>
                                             <div class="controls">
                                                <input type="text" name="zaragoza" value=<?php echo $row[ 'zaragoza']; ?>>
                                             </div>
                                          </div>
                                          <div class="control-group">
                                             <label class="control-label" for="inputmayapyap">Mayapyap</label>
                                             <div class="controls">
                                                <input type="text" name="mayapyap" value=<?php echo $row[ 'mayapyap']; ?>>
                                             </div>
                                          </div>
                                          <div class="control-group">
                                             <label class="control-label" for="inputpenaranda">Penaranda:</label>
                                             <div class="controls">
                                                <input type="text" name="penaranda" value=<?php echo $row[ 'penaranda']; ?>>
                                             </div>
                                          </div>
                                          <div class="control-group">
                                             <label class="control-label" for="inputcalaanan">Calaanan:</label>
                                             <div class="controls">
                                                <input type="text" name="calaanan" value=<?php echo $row[ 'calaanan']; ?>>
                                             </div>
                                          </div>
                                          <div class="control-group">
                                             <label class="control-label" for="inputpalali">Palali:</label>
                                             <div class="controls">
                                                <input type="text" name="palali" value=<?php ob_start() echo $row[ 'palali']; ?>>
                                             </div>
                                          </div>
                                          <div class="control-group">
                                             <label class="control-label" for="inputsan_isidro">San Isidro:</label>
                                             <div class="controls">
                                                <input type="text" name="san_isidro" value=<?php echo $row[ 'san_isidro']; ?>>
                                             </div>
                                          </div>
                                          <div class="control-group">
                                             <label class="control-label" for="inputarayat">Arayat:</label>
                                             <div class="controls">
                                                <input type="text" name="arayat" value=<?php echo $row[ 'arayat']; ?>>
                                             </div>
                                          </div>
                                          <div class="control-group">
                                             <label class="control-label" for="inputcandaba">Candaba:</label>
                                             <div class="controls">
                                                <input type="text" name="candaba" value=<?php echo $row[ 'candaba']; ?>>
                                             </div>
                                          </div>
                                          <div class="control-group">
                                             <label class="control-label" for="inputsibul_spring">Sibul Spring:</label>
                                             <div class="controls">
                                                <input type="text" name="sibul_spring" value=<?php echo $row[ 'sibul_spring']; ?>>
                                             </div>
                                          </div>
                                          <div class="control-group">
                                             <label class="control-label" for="inputsasmuan">Sasmuan:</label>
                                             <div class="controls">
                                                <input type="text" name="sasmuan" value=<?php echo $row[ 'sasmuan']; ?>>
                                             </div>
                                          </div>
                                          <div class="control-group">
                                             <label class="control-label" for="inputsulipan">Sulipan:</label>
                                             <div class="controls">
                                                <input type="text" name="sulipan" value=<?php echo $row[ 'sulipan']; ?>>
                                             </div>
                                          </div>
                                          <div class="control-group">
                                             <label class="control-label" for="inputmexico">Mexico:</label>
                                             <div class="controls">
                                                <input type="text" name="mexico" value=<?php echo $row[ 'mexico']; ?>>
                                             </div>
                                          </div>
                                          <div class="control-group">
                                             <label class="control-label" for="inputporac">Porac:</label>
                                             <div class="controls">
                                                <input type="text" name="porac" value=<?php echo $row[ 'porac']; ?>>
                                             </div>
                                          </div>
                                          <div class="control-group">
                                             <label class="control-label" for="inputsan_rafael">San Rafael:</label>
                                             <div class="controls">
                                                <input type="text" name="san_rafael" value=<?php echo $row[ 'san_rafael']; ?>>
                                             </div>
                                          </div>
                                          <div class="control-group">
                                             <div class="controls">

                                                <button type="submit" name="update" class="btn btn-success" style="margin-right: 65px;">Save</button>
                                                <a href="index.php" class="btn">Back</a>
                                             </div>
                                          </div>
                                       </form>
                                       <?php


                            $id=$_REQUEST['id'];


$sql= "select * from rainfallstations_copy where id='$ID'" ;
$result = mysqli_query($con,$sql) or die('Error: ' . mysqli_error($con));
$test = mysqli_fetch_array($result);
if (!$result)
        {
        die("Error: Data not found..");
        }
else
{
                                    $munoz= $test['munoz'];
                                    $sapang_buho= $test['sapang_buho'];
                                    $gabaldon= $test['gabaldon'];
                                    $zaragoza= $test['zaragoza'];
                                    $mayapyap= $test['mayapyap'];
                                    $penaranda= $test['penaranda'];
                                    $calaanan= $test['calaanan'];
                                    $palali= $test['palali'];
                                    $san_isidro= $test['san_isidro'];
                                    $arayat= $test['arayat'];
                                    $candaba= $test['candaba'];
                                    $sibul_spring= $test['sibul_spring'];
                                    $sasmuan= $test['sasmuan'];
                                    $sulipan= $test['sulipan'];
                                    $mexico= $test['mexico'];
                                    $porac= $test['porac'];
                                    $san_rafael= $test['san_rafael'];
if (isset($_POST['update'])) {
                                    $munoz_save= $_POST['munoz'];
                                    $sapang_buho_save= $_POST['sapang_buho'];
                                    $gabaldon_save= $_POST['gabaldon'];
                                    $zaragoza_save= $_POST['zaragoza'];
                                    $mayapyap_save= $_POST['mayapyap'];
                                    $penaranda_save= $_POST['penaranda'];
                                    $calaanan_save= $_POST['calaanan'];
                                    $palali_save= $_POST['palali'];
                                    $san_isidro_save= $_POST['san_isidro'];
                                    $arayat_save= $_POST['arayat'];
                                    $candaba_save= $_POST['candaba'];
                                    $sibul_spring_save= $_POST['sibul_spring'];
                                    $sasmuan_save= $_POST['sasmuan'];
                                    $sulipan_save= $_POST['sulipan'];
                                    $mexico_save= $_POST['mexico'];
                                    $porac_save= $_POST['porac'];
                                    $san_rafael_save= $_POST['san_rafael'];

$sql= "UPDATE rainfallstations_copy SET munoz = '$munoz_save' , sapang_buho = '$sapang_buho_save' , gabaldon ='$gabaldon_save', zaragoza = '$zaragoza_save' , mayapyap ='$mayapyap_save',penaranda = '$penaranda_save' , calaanan = '$calaanan_save' , palali ='$palali_save',san_isidro = '$san_isidro_save' , arayat ='$arayat_save',candaba = '$candaba_save' , sibul_spring = '$sibul_spring_save' , sasmuan ='$sasmuan_save',sulipan = '$sulipan_save' , mexico ='$mexico_save',porac = '$porac_save' , san_rafael = '$san_rafael_save' WHERE id = '$id'" ;
$result = mysqli_query($con,$sql) or die('Error: ' . mysqli_error($con));
header('Location:index.php');}
}
?>

                                 </center>


                              </div>
                           </div>
                        </div>
                     </div>
                  </div>
               </div>
            </div>
         </div>
      </div>

   </body>

   </html>

2 个答案:

答案 0 :(得分:1)

问题是您要发送内容(请参阅<input type="text" name="palali" ...),之后您尝试发送标头(header('Location:index.php')。您必须在发送内容之前设置标头值。其他解决方案是使用ob_start函数打开输出缓冲。但是在将任何内容写入输出之前必须使用ob_start,所以在你的情况下你需要这个:

<?php ob_start();?>
<input type="text" name="palali"  value=<?php echo $row['palali']; ?>>
header('Location:index.php');}

我想知道为什么在发送重定向标题时发送内容...

答案 1 :(得分:0)

headers already sent当您在标头之前首先发送内容时,通常会出现此错误。所以在发送标题之前没有输出!

必须在进行任何输出之前调用发送/修改HTTP标头的函数。

为避免此错误,请始终在ob_start之后添加<?php。 使用header永远不会忘记在标题后放置exit();die(),还有一件事。