Javascript 删除并重定向到php中的页面

Javascript 删除并重定向到php中的页面,javascript,php,Javascript,Php,我正在尝试删除php中的条目,并在php中重定向页面。 我需要根据条件将页面重定向为标题(“Location:report2.php?region=$region”)删除后页面不会重定向到标题(“位置:report2.php?region=$region”) 它也不会删除。它只重定向到report2.php?delete_id=103 这是密码 ?php //Give your mysql username password and database name include_once "d

我正在尝试删除php中的条目,并在php中重定向页面。 我需要根据条件将页面重定向为
标题(“Location:report2.php?region=$region”)删除后页面不会重定向到
标题(“位置:report2.php?region=$region”)
它也不会删除。它只重定向到report2.php?delete_id=103
这是密码

  ?php
//Give your mysql username password and database name
include_once "db.php";
if(isset($_REQUEST['region']))
{
$region=$_REQUEST['region'];

//connection to the database


$qresult = mysql_query("SELECT * FROM registration where region='".$region."'");

    echo "<h1>Registration Details of $region Region.</h1>";
if (mysql_num_rows($qresult) == 0) { 
echo "<h3 style=color:#0000cc;text-align:center;>No Registrations Done..!</h3>"; 
} else { 


        echo "<table border='1' cellpadding='0' cellspacing='0' class='reports'>";

        echo "<tr>" .
                    "<td style='background: #f1f1f1; font-weight: bold;text-align:center;'>Registration Number</td>" .
                    "<td style='background: #f1f1f1; font-weight: bold;text-align:center;'>Name</td>" . 
"</tr>";

        while($row = mysql_fetch_assoc($qresult)) { 
                       echo "<tr>" .
                    "<td style=text-align:center;>" . $row['id'] . "</td>" . 

                    "<td style=text-align:center;>".  $row['name']  . "</td>"; 


                ?>

              <td><a href="javascript:delete_id(<?php echo $row['id']; ?>)"><img src="images/delete21.png" alt="Delete" /></a></td>


                    </tr>
        <?php   
        }
        }}
        ?>
        </table>
 <?php
 if(isset($_GET['delete_id']))
  {
    $sql_query="DELETE FROM registration WHERE id=".$_GET['delete_id'];
    mysql_query($sql_query);

    header("Location: report2.php?region=$region");
    exit;
  }

?>  
?php
//提供您的mysql用户名、密码和数据库名称
包括一次“db.php”;
如果(isset($_请求['region']))
{
$region=$_请求['region'];
//与数据库的连接
$qresult=mysql_查询(“从registration中选择*,其中region=''.$region.''.”);
echo“注册$region的详细信息。”;
如果(mysql_num_rows($qresult)==0){
echo“未完成注册…”;
}否则{
回声“;
“回声”。
“注册号”。
“姓名”。
"";
而($row=mysql\u fetch\u assoc($qresult)){
“回声”。
“.$row['id']”。
“.$row['name']”;
?>

我认为您的问题是由于格式错误,因此您没有注意到您的if没有在下一个if语句之前关闭,我认为这不是您的本意

这是您的固定和格式化代码:

<?php

  include_once "db.php";
  if(isset($_REQUEST['region'])) 
  {
    $region=$_REQUEST['region'];

    $sql_query="SELECT * FROM registration where region='".$region."' ";
    $result_set=mysql_query($sql_query);
  }
  if(isset($_GET['delete_id']))
  {

    $sql_query="SELECT * FROM registration where id='".$_GET['delete_id']."' ";
    $result=mysql_query($sql_query);
    while($row = mysql_fetch_assoc($result)) { 
      $region = $row['region'];
    }

    $sql_query="DELETE FROM registration WHERE id=".$_GET['delete_id'];
    mysql_query($sql_query);

    header("Location: report2.php?region=".$region);
    exit;
  }

?>
<script type="text/javascript">
    function delete_id(id) {
      if(confirm('Sure To Remove This Record ?')) {
          window.location.href='report2.php?delete_id='+id;
        }
    }
</script>

在哪里设置“region”?我认为这就是为什么它不起作用的原因,因为region从未设置,因此它从未执行if-statement中的代码。在使用
header
函数之前,您不能输出任何内容,这里不是这样。您设置的所有内容都是delete\u id1。不要使用不推荐使用的
mysql\u*
-函数ns。从PHP5.5开始,它们就被弃用,在PHP7中被完全删除。使用MySQLi或PDO代替。2.您对查询非常开放,并且应该真正使用而不是连接查询,如果您使用上述MySQLi或PDO,可以使用这些查询。实际上,当用户使用用户名、密码和区域登录时,会出现adminlogin。登录后,它会重新登录rects to header(“Location:report2.php?region=$region”);这很好。使用delete选项时,我无法将其重定向到同一页面。好的,将其更改回去,认为这是一个键入错误,我的错误:)@user6582683-您需要将php块移动到文件顶部,在JS或任何其他输出或
头之前(“地点:……”)
不起作用。正如其中一条评论所说,在发送标题之前,你不能输出任何内容。你应该在标题之后加入一个
退出;
,以确保脚本不会继续执行。谢谢,更改了它。确保你的html/js代码的其余部分也低于此值。删除后,我更改了代码并重定向到。不显示区域名称。