【问题标题】:How can I use PHP to automatically change the page if [closed]如果[关闭],我如何使用 PHP 自动更改页面
【发布时间】:2023-03-06 08:38:02
【问题描述】:

...if 语句的条件是否满足?

如果满足某些条件,我有一些代码可以将数据添加到数据库,添加数据后我希望页面重定向到另一个页面?我该怎么做?

【问题讨论】:

  • header('location: /page2.php');

标签: php mysql database url hyperlink


【解决方案1】:

使用 if-else 条件。你可以使用 PHP 的 header() 。

if(/* Your conditions */){
// redirect if fulfilled
header("Location:nxtpage.php");
}else{
//some another operation you want
}

【讨论】:

    【解决方案2】:

    你应该使用 header php 函数

    <?php 
    
      //some conditions
    
      header("Location: http://www.example.com/");
    
    ?>
    

    【讨论】:

      【解决方案3】:

      试试这个代码

       $query ="insert into test values (1,'test')";
      
      if(mysql_query($query) == true)
      {
        header('location:index.php');
        exit();
      }
      else
      {
        echo " insert failed";
      }
      

      【讨论】:

        【解决方案4】:

        试试PHP Header:

        header('位置:http://www.example.com/');

        【讨论】:

          猜你喜欢
          • 2023-01-12
          • 2019-08-15
          • 1970-01-01
          • 2021-09-17
          • 2014-06-18
          • 1970-01-01
          • 1970-01-01
          • 2015-12-06
          • 2021-08-11
          相关资源
          最近更新 更多