2017-03-21 73 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