2017-06-29 108 views
1

这是我的代码和PHP的Header()函数不能帮助我,有人可以帮我找到我的错误或其他解决方案吗? 执行后,这个查询“DELETE FROM PAGOS其中id = $ id为”不回我tabla_pagos.php如何执行php中的表单后返回上一页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

From manual“请记住,在发送任何实际输出之前,必须调用header(),或者通过普通的HTML标签,文件中的空行或PHP。”所以......包含文件中包含什么内容? http://php.net/manual/en/function.header.php – Andreas

+0

那么会发生什么? – TimBrownlaw

+0

嗨安德烈亚斯!在我的包含文件中,我只有连接到数据库 –

回答

0

从你的评论到马特的回答,似乎你已经在你的文件menu.php输出。

在header()函数之前,您不能有任何输出。
http://php.net/manual/en/function.header.php

记住header()函数被发送任何实际输出之前,必须被调用,或者通过正常的HTML标记,空行的文件,或者从PHP。使用include或require函数或其他文件访问函数读取代码,并在调用header()之前输出空格或空行是非常常见的错误。使用单个PHP/HTML文件时存在同样的问题。

+0

THAANKS,非常感谢,您的帮助非常有用,我删除了一个不必要的要求,它起作用 –

+0

您确定没有必要吗?通常需要的是......必需的......如果我的回答是正确的,您可以接受我答案左侧的答案。 – Andreas

0

您需要包括以阻止进一步的页面处理您的通话header("Location: tabla_pagos.php");exit;通话。

<?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看到更多。

+0

嗨马特溜冰场!我做了这些改变,但它给我一个警告。 - 警告:无法修改标头信息 - /home/cimacomu/epokavirtual.com/cimacomunidad/eliminar.php中已发送的标头(输出开始于/home/cimacomu/epokavirtual.com/cimacomunidad/templates/menu.php:26)在线17 –

+0

@Frida告诉你在头部之前有一些输出,就像我在我的评论中提到的那样。 – Andreas

+0

Menu.php听起来像输出在我的耳朵.... – Andreas