我有一个错误无法修改标题信息 - 标题已经发送,我已经查看了答案, 在开始php之前没有空格,并且使用ob_start和flush ..
它工作在我的其他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>
这是代码
<?php
$id = $_GET['delete_truk'];
$sql="DELETE FROM `truk` WHERE `trukid` = '$id' ";
$query = mysql_query($sql);
header('Location:index.php?truck');
?>
并且它无法重定向警告:无法修改标头信息 - 已经发送的标头(输出已启动
)感谢您的帮助, 抱歉英文不好
答案 0 :(得分: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');