2017-03-21 71 views
1

我在形式創造了一個基本標誌:登錄將無法工作

<form action = "" type = "post"> 
<input type = "text" name = "txt_user" placeholder = "Username" required/> 
<input type = "password" name = "txt_pass" placeholder = "Password" required/> 
<input type = "submit" name = "btn_submit" value = " Sign In "> 

,並張貼這上面我的html:

<?php 
    if(isset($_POST['btn_submit'])) { 
    $username = $_POST['txt_user']; 
    echo $username; 
?> 

,看看形式的作品,它不。該txt_user將不會顯示了頂部的HTML所應當,而是從這個改變我的網址:
localhost:8080/tryouts

這樣:
http://localhost:8080/tryout/?si_username=asd&si_password=asdasd&si_submit=++Sign+In++



你能告訴我這是怎麼回事?我之前嘗試過這種方法,它工作。也許我錯了什麼東西?

更新
包含表單的頁面被稱爲signin.php那裏它被放在裏面index.php這樣的:

<body> 
<?php include("signin.php"); ?> 

</body> 

目的是節省時間和空間的PHP代碼,這樣我不會麻煩地改變頁面之間的形式登錄,而只是改變了登錄頁面主頁面。我不認爲這是造成這個,但仍然...

+0

當表單數據被傳遞到URL,例如'?param = value&param2 = value2'時,您應該明白表單類型是GET而不是POST。 '

'應該歸因於'方法'而不是類型。我想你從AJAX中弄混了。 –

回答

0

您需要將您的form method設置爲POST; form type無效。現在,它默認使用GET

<form action = "" method = "post"> 
<input type = "text" name = "txt_user" placeholder = "Username" required/> 
<input type = "password" name = "txt_pass" placeholder = "Password" required/> 
<input type = "submit" name = "btn_submit" value = " Sign In "> 
+0

非常感謝!這工作! – Dranreb

+0

很高興聽到它。 :) – kittykittybangbang