登录将无法正常工作

时间:2017-03-21 18:34:47

标签: php html html5

我已经创建了一个基本的签到形式:

<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代码的时间和空间,这样我就不会在页面之间更改登录表单,只需更改登录页面的主页面。我认为这不会导致这种情况,但仍然......

1 个答案:

答案 0 :(得分: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  ">