2012-04-18 34 views
2

... if語句的條件滿足了?如何使用PHP自動更改頁面如果

我有一些代碼添加數據到數據庫,如果滿足某些條件,數據添加後我希望頁面重定向到另一個頁面?我怎樣才能做到這一點?

+0

'header('location:/page2.php');'' – Rufinus 2012-04-18 11:34:23

回答

3

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

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

你建議立即進行刪除使用頭PHP函數

<?php 

    //some conditions 

    header("Location: http://www.example.com/"); 

?> 
1

試試這個代碼

$query ="insert into test values (1,'test')"; 

if(mysql_query($query) == true) 
{ 
    header('location:index.php'); 
    exit(); 
} 
else 
{ 
    echo " insert failed"; 
} 
相關問題