如何使用php在条件下重定向

如何使用php在条件下重定向,php,html,mysql,css,if-statement,Php,Html,Mysql,Css,If Statement,我对php中的重定向有疑问 我有两页 -索引的第一页 -第二页用于流程编辑或edit.php 我的问题是…… 如果我单击edit,他肯定在edit.php中,如果我单击save in edit.php 如果我的重定向代码 header('location:index.php') 如何返回或重定向到索引,但仍处于logical2或 $\u POST['select']='2' 这是我的代码: <form action='' methode='post'> <select na

我对php中的重定向有疑问
我有两页
-索引的第一页
-第二页用于流程编辑或edit.php

我的问题是……
如果我单击edit,他肯定在edit.php中,如果我单击save in edit.php
如果我的重定向代码
header('location:index.php')

如何返回或重定向到索引,但仍处于logical2或
$\u POST['select']='2'

这是我的代码:

<form action='' methode='post'>
  <select name='select'>
  <option value='1'>example1</option>
  <option value='2'>example2</option>
  </select>
</form>
<?php
if($_POST['select']=='1')
{
echo"<a href='?page=edit&id=$r[id]'>Edit</a>";
}
elseif($_POST['select']=='2')
{
echo"<a href='?page=edit&id=$r[id]'>Edit</a>";
}
else
{
echo"please select";
}
?>

例1
例2

标题,如果您有它们,必须是输出到浏览器的第一件事。这包括在打开

例1
例2

希望这有帮助

您需要在这两个
$r[id]
周围放上大括号(
{}
)。除此之外,我不知道你们在问什么。如果我的代码不完整,我很抱歉,因为这只是个例子,但我的问题更像是重定向头('location:index.php');但是如何指向索引,但仍处于条件$_POST['select']='2'
<?php
if($_POST['select']=='1')
{
    header('Location: http://yoursite.com/index.php');
}
elseif($_POST['select']=='2')
{
echo"<a href='?page=edit&id={$r[id]}'>Edit</a>";
}
else
{
echo"please select";
}
?>
<form action='edit.php' method='post'>
  <select name='select'>
  <option value='1'>example1</option>
  <option value='2'>example2</option>
  </select>
</form>