2014-01-23 56 views
-5

我有一个错误不能更改头信息 - 头已经发出,我已经开始PHP之前虽然检查出答案, 没有空间,并使用ob_start和冲洗..不能更改头信息,不能重定向

它的工作对我的其他PHP文件(插入,编辑),但它不是删除脚本唯一的工作,但实际上我想删除被删除的行..

这是我的页面调用代码

<script> 
function confirmation(id){ 
var message = "are you sure?"; 
var konfirmasi = confirm(message); 
if(konfirmasi == true) { 
window.location="index.php?delete_truk="+ id; 
} 
else { 

} 
} 
</script> 
<?php 
     $query = "SELECT * FROM truk"; 
     $sql=mysql_query($query); 
    ?>   
     <table class="show_data" id="truk"> 
      <tr> 
       <td>Truk ID</td> 
       <td>Tipe</td> 
       <td>images</td> 
       <td>Deskripsi</td> 
       <td>jumlah</td> 
       <td>Delete/Edit</td> 
      </tr> 
      <?php 
       while($fetch=mysql_fetch_array($sql)){ 
      ?> 
      <tr> 

       <td><?php echo $fetch['trukid']; ?></td> 
       <td style="width:100px;"><?php echo $fetch['tipe']; ?></td> 
       <td><?php echo $fetch['images']; ?></td> 
       <td><?php echo substr($fetch['deskripsi'],0,50); ?></td> 
       <td><?php echo $fetch['jumlah']; ?></td> 

       <td> 

       <input type="image" class="icon" src="images/asset/delete.jpg" onClick="confirmation('<?php echo $fetch['trukid']; ?>') "> 
       <a href="index.php?edit_truk=<?php echo $fetch['trukid']; ?>"><img class="icon" src="images/asset/edit.jpg"></a> 
       </td> 
      </tr> 
      <?php } ?> 
     </table> 
     <a href="index.php?input_truk" class="button">Tambah Truk</a> 

here是代码

<?php 
$id = $_GET['delete_truk']; 
$sql="DELETE FROM `truk` WHERE `trukid` = '$id' "; 
$query = mysql_query($sql); 
header('Location:index.php?truck'); 
?> 

,它不能重定向,而不是警告:不能更改头信息 - 头已经发出(输出开始

感谢您的帮助,, 抱歉不好英语

+0

remove echo()并确保你的代码在html代码上面 – sunshinekitty

+0

@ 0n35啊对不起,先生,我忘了把页面称为代码,我已经编辑我的文章,你可以看看吗?谢谢 – user3158183

回答

0

你不能重定向如果你开始写入页面

$id = $_GET['delete_truk']; 
$sql="DELETE FROM `truk` WHERE `trukid` = '$id' "; 
//echo $sql; <-- don't echo 
$query = mysql_query($sql); 
header('Location:index.php?truck'); 
+3

这是大多数日子的问题,请投票关闭,而不是回答 – 2014-01-23 01:26:16

+0

对不起,我确实想过寻找重复,但我投了 – meda

+0

我已经删除了echo $ sql;但仍然不能先生 – user3158183