【发布时间】:2023-03-06 08:38:02
【问题描述】:
...if 语句的条件是否满足?
如果满足某些条件,我有一些代码可以将数据添加到数据库,添加数据后我希望页面重定向到另一个页面?我该怎么做?
【问题讨论】:
-
header('location: /page2.php');
标签: php mysql database url hyperlink
...if 语句的条件是否满足?
如果满足某些条件,我有一些代码可以将数据添加到数据库,添加数据后我希望页面重定向到另一个页面?我该怎么做?
【问题讨论】:
header('location: /page2.php');
标签: php mysql database url hyperlink
使用 if-else 条件。你可以使用 PHP 的 header() 。
if(/* Your conditions */){
// redirect if fulfilled
header("Location:nxtpage.php");
}else{
//some another operation you want
}
【讨论】:
你应该使用 header php 函数
<?php
//some conditions
header("Location: http://www.example.com/");
?>
【讨论】:
试试这个代码
$query ="insert into test values (1,'test')";
if(mysql_query($query) == true)
{
header('location:index.php');
exit();
}
else
{
echo " insert failed";
}
【讨论】:
试试PHP Header:
header('位置:http://www.example.com/');
【讨论】: