如果出现以下情况,我如何使用 PHP 自动更改页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10208442/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I use PHP to automatically change the page if
提问by Andrew Fairbairn
...the conditions of an if statement are fulfilled?
... if 语句的条件是否满足?
I have some code to add data to a database if certain conditions are met, after the data is added I want the page to redirect to another page? How can I do this?
如果满足某些条件,我有一些代码可以将数据添加到数据库,添加数据后我希望页面重定向到另一个页面?我怎样才能做到这一点?
回答by Dhruvisha
Use if-else condition. You can use header() of PHP .
使用 if-else 条件。您可以使用 PHP 的 header() 。
if(/* Your conditions */){
// redirect if fulfilled
header("Location:nxtpage.php");
}else{
//some another operation you want
}
回答by Nebojsa
You shoul use header php function
你应该使用header php函数
<?php
//some conditions
header("Location: http://www.example.com/");
?>
回答by Naveen Kumar
try this code
试试这个代码
$query ="insert into test values (1,'test')";
if(mysql_query($query) == true)
{
header('location:index.php');
exit();
}
else
{
echo " insert failed";
}
回答by GoSmash
Try PHP Header:
尝试PHP 标头:
header('Location: http://www.example.com/');
header('位置:http: //www.example.com/');

