这是我的代码,PHP的Header()函数对我没有帮助,有人可以帮我找到我的错误或其他解决方案吗? 执行此查询后“DELETE FROM pagos where id = $ id”不要将我返回tabla_pagos.php
<?php
include "app/conexionqa.php";
require("templates/menu.php");
$id=$_GET["parametro"];
$data = $conn -> query("SELECT * FROM pagos where id=$id" );
if(isset($_POST['eliminar'])){
$idAdmin=$_POST["idAdmin"];
$fPago=$_POST["fPago"];
$status=$_POST["status"];
$montoPagar=$_POST["montoPagar"];
$sql= $conn -> query("DELETE FROM pagos where id=$id");
header("Location: tabla_pagos.php");
}?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<br>
<br>
<section class="header__user">
<!--<div id="edit" class="modal">-->
<div class="modal-content">
<h3 class="center unbutu loginTitle blue-text">Eliminar registro</h3>
<?php foreach($data as $campo){?>
<form action="#" method="post">
<label>Id</label>
<p><?php echo $id; ?></p>
<label>Invitado por:</label>
<input type="text" name="idAdmin" value="<?php echo $campo['idAdmin']; ?>"/>
<label>Fecha de pago</label>
<input type="text" name="fPago" value="<?php echo $campo['fPago']; ?>"/>
<label>Status</label>
<input type="text" name="status" value="<?php echo $campo['status']; ?>"/>
<label>Cantidad ultimo pago</label>
<input type="text" name="montoPagar" value="<?php echo $campo['montoPagar']; ?>"/>
<button class="btn waves-effect waves-light" type="submit" name="eliminar">Eliminar
</button>
<a href="tabla_pagos.php"> Cancelar</a>
</form>
<?php } ?>
</div>
</div>
</section>
</body>
</html>
<?php require("templates/footer.php");
?>
答案 0 :(得分:0)
您需要在exit;
来电后跟header("Location: tabla_pagos.php");
拨打电话,以便停止进一步的网页处理。
<?php
include "app/conexionqa.php";
require("templates/menu.php");
$id=$_GET["parametro"];
$data = $conn -> query("SELECT * FROM pagos where id=$id" );
if(isset($_POST['eliminar'])){
$idAdmin=$_POST["idAdmin"];
$fPago=$_POST["fPago"];
$status=$_POST["status"];
$montoPagar=$_POST["montoPagar"];
$sql= $conn -> query("DELETE FROM pagos where id=$id");
header("Location: tabla_pagos.php");
exit;
}?>
header()
的PHP文档在其示例中显示了这一点:
<?php
header("Location: http://www.example.com/"); /* Redirect browser */
/* Make sure that code below does not get executed when we redirect. */
exit;
?>
您可以在http://php.net/manual/en/function.header.php找到更多信息。
答案 1 :(得分:0)
从您的评论到Matt的答案,您的文件menu.php中有输出。
在header()函数之前不能有任何输出。
http://php.net/manual/en/function.header.php
请记住,在发送任何实际输出之前,必须通过普通HTML标记,文件中的空行或PHP来调用header()。使用include或require,函数或其他文件访问函数读取代码是一个非常常见的错误,并且在调用header()之前输出空格或空行。使用单个PHP / HTML文件时存在同样的问题。