PHP重定向

时间:2012-03-13 13:48:20

标签: php mysql

我有一个数据库,在重定向之后我想要一个表行来显示使用该行id的行信息。我该如何输入?

我构建了一个edit.php和一个login.php,现在我点击编辑然后重定向到登录,现在我正确登录后重定向到edit.php,问题是edit.php没有显示行可供我编辑。

假设这是所有需要的代码,我该如何纠正:

if($hash == $results[0]['hash']) 
{ $_SESSION['user_id'] = $results[0]['id'];
redirect(''); } else $errors['username'] = 'Login failed.';

好的,这是现在正在运行的代码:

if($hash == $results[0]['hash']) 
{ $_SESSION['user_id'] = $results[0]['id'];
Header( "Location: http://localhost/flagship/web/edit.php?id=" . $_SESSION['user_id'] ); }
else $errors['username'] = 'Login failed.';

只是它只从表中获取第一行,如何才能显示其他行?

5 个答案:

答案 0 :(得分:4)

使用header功能:

header('location: ../web/edit.php?id=' . $row[$id]);

答案 1 :(得分:0)

我认为你在寻找:

header("Location: ../web/edit.php?id=$row[$id]");

答案 2 :(得分:0)

您想重定向浏览器吗?试试这个:

Header( "Location: http://www.domain.com/web/edit.php?id=" . $row[$id] );

修改

现在您的问题中的代码将是:

if($hash == $results[0]['hash']) 
{ $_SESSION['user_id'] = $results[0]['id'];
Header( "Location: http://www.domain.com/web/edit.php?id=" . $_SESSION['user_id'] ); } else $errors['username'] = 'Login failed.';

答案 3 :(得分:0)

Header('Location:edit.php?id='.$row[$id].'');

答案 4 :(得分:-3)

如果你必须使用php来执行此操作:http://php.net/manual/en/function.header.php

我个人最喜欢的重定向方式是

echo "<script>window.location('set location');</script>";