簡體   English   中英

用戶單擊提交按鈕時如何調用兩個不同的網頁?

[英]How to call two different webpages when the user clicks submit button?

我的代碼如下所示:

<form action="register.php" method="post">
  <input type="text" name="uname">
  <input type="submit" >
</form>

在register.php文件中,我有一個數據庫連接代碼。 如果數據庫通過register.php文件連接,則在同時提交表單后,我需要加載另一個html頁面。

怎么做?

注冊成功后,只需通過header()函數將用戶重定向到第二頁:

index.php:

<form action="register.php" method="post">
  <input type="text" name="uname">
  <input type="submit" >
</form>

register.php:

// Process registration
if (valid) {
  header('success.php);
}

success.php:

// Thank the user for registering

另外,您總是可以簡單地在register.php本身上處理success頁面。

希望這可以幫助! :)

歡迎來到SO。 在我看來,您實際上不需要同時加載2個URL,而您要查找的是if語句,僅當設置了post數據時才執行一些代碼

if(!empty($_POST)){
  //code to execute when form is submitted
}
else {
  //code to execute otherwise
}

如果確實需要同時向2個URL發出請求,則正在尋找AJAX請求。

有關您的設置和最終目標的問題中的更多詳細信息將有助於進一步幫助。

在您的Register.Php添加類似這樣的內容檢查您的Sql結果類似這樣的內容

$sql='select * Tablename where condition'

$result= fetch($sql)
$row=fetch_array($result)asdsad
if($row>0){
header(Location:'connected.php') // whatever your html
}
else {header(Location:"failed.php")//whenever query got no row
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM