2013-01-16 97 views
1

我只是進入MySQL,我正在創建一個基本的註冊頁面。然而,當我點擊提交時,我想要被引導到另一個頁面,說你登錄的頁面,儘可能多的網站。添加一個鏈接到一個HTML提交按鈕

如何讓提交按鈕鏈接到新頁面。我知道這會很簡單,但我看起來似乎並沒有發現太多。

這是我試過的當前代碼:

<html> 

<head> 
    <title>MySQL Test - Registration</title> 
    <script LANGUAGE="JavaScript"> 
     function testResults() { 
     window.document.location.href = "http://www.google.com"; 
     } 
    </script> 
</head> 

<body> 
    <form action = "rego.php" method = "POST"> 
     Username:<br/> 
     <input type = "text" name = "username"/><br/> 
     Password:<br/> 
     <input type = "password" name = "password"/><br/> 
     Confirm Password:<br/> 
     <input type = "password" name = "passvery"/><br/> 
     Email:<br/> 
     <input type = "text" name = "email"/><br/><br/> 

     Please select your gender:<br/> 
     <input type = "radio" name = "gender" value = "male"/>Male &nbsp&nbsp&nbsp&nbsp&nbsp 
     <input type = "radio" name = "gender" value = "female"/>Female<br/><br/> 

     <input type = "checkbox" name = "agree" value = "agree"/>I agree to the terms and conditions.<br/> 
     <br/> 
     <input type = "submit" value = "Sign Up!" onclick = "javascript:testresults()" /> 

    </form> 
</body> 
</html> 
+0

爲什麼不直接從你的'rego.php重定向'腳本? – jackbot

+0

你是什麼意思? – ReallyGoodPie

+0

您希望在rego.php中進行一些處理(即向數據庫添加記錄或通知用戶他們已經使用該電子郵件地址進行了註冊)。因此,在插入新記錄後,將用戶重定向到登錄頁面。 – jackbot

回答

6

錶行動=「rego.php」意味着你的表格將被提交到該文件。

如果你想要去rego.php後別的地方,你應該從該文件中使用位置標頭重定向,例如,任何輸出前:

// do stuff (registration) 

header("Location: another-php.php"); 
+0

啊我已經完全忘記了這個:(我在很長一段時間裏沒有用PHP/HTML編寫,基本上只是重新開始。謝謝! – ReallyGoodPie

+0

我發現了一個問題這是,如果我想回到註冊頁面,我不能,它只是將我重定向到標題頁。有沒有辦法解決這個問題? – ReallyGoodPie

+0

「回去」是什麼意思?如果出現錯誤,重新顯示註冊表單可以使用if(registrationSuccess()){redirect} else {再次顯示錶單} – Dutow