登录按钮不起作用

时间:2016-01-26 20:06:36

标签: php

我是网络开发的新手,想要制作一个简单的登录表单,虽然不知道为什么我的登录按钮没有响应,但用户需要输入他们的电子邮件密码。一旦用户输入密码,登录按钮就不起作用。

 <?php
 session_start();



    if(isset($_POST['submit'])) {
        include_once("php/config/database.php"); 
        $Email = strip_tags($_POST['Email']);
        $dbPassword = strip_tags($_POST['Password']);

        $Email = stripslashes($Email);
        $dbPassword = stripslashes($dbPassword);

        $Email = mysqli_real_escape_string($conn, $Email);
        $dbPassword = mysqli_real_escape_string($conn, $dbPassword);

        $dbPassword = md5($dbPassword);

        $sql = ("SELECT * FROM 'Users' WHERE Email='$Email' LIMIT 1");
        $query = mysqli_query($conn, $sql);
        $row = mysqli_fetch_array($query);
        $UserID = $row['UserID'];
        $dbpass_Password = $row['Password'];

        if($dbPassword == $dbpass_Password) {
            $_SESSION['Email'] = $Email;
            $_SESSION['UserID'] = $UserID;
            header("Location: account.php");
        } 
        else 
        {
            echo "You didn't enter the correct details!";
        }

    } 


?>


        <html >
          <head>
            <meta charset="UTF-8">
            <title>background</title>




                <link rel="stylesheet" href="css/style.css">
         <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>

             <script src="js/index.js"></script>




          </head>

          <body>


            <div class="container demo-1">





              <div class="content">

                <div id="large-header" class="large-header">

              <form  action="index.php" method="POST>  
                  <div class="box">


              <h1 id="logintoregister">Login</h1>


          <div class="group show">      
              <input class="inputMaterial" type="text" name="FirstName" >
              <span class="highlight"></span>
              <span class="bar"></span>
              <label>First Name</label>
              </div>
            <div class="group show">      
              <input class="inputMaterial" type="text" name="Surname" >
              <span class="highlight"></span>
              <span class="bar"></span>
              <label>Surname</label>
              </div>


             <div class="group ">      
              <input class="inputMaterial" type="email" name="Email" >
              <span class="highlight"></span>
              <span class="bar"></span>
              <label>Email</label>
              </div>

            <div class="group">      
              <input class="inputMaterial" type="password" id="password" name="Password" >
              <span class="highlight"></span>
              <span class="bar"></span>
              <label>Password</label>
              </div>
            <div class="group show">      
              <input class="inputMaterial" type="password"  id="confirm_password" >
              <span class="highlight"></span>
              <span class="bar"></span>
              <label>Confirm Password</label>
              </div>


        <button id="buttonlogintoregister"  type = "submit" name="submit">Login</button>

          <p id="plogintoregister">By registering, You accept all terms and conditons </p>
          <p id="textchange" onclick="register()"> Sign Up</p>


                 </form> 




              <!-- Related demos -->




         <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>

             <script src="js/index.js"></script>


        </body>
        </html>

1 个答案:

答案 0 :(得分:1)

你的HTML坏了:

      <form  action="index.php" method="POST" />  
                                              ^---

您自动关闭了表单标记,因此您网页上的每个输入字段都是表单的 OUTSIDE

另外请注意,您还有其他逻辑错误:

        if($Password == $dbpass_Password) {
              ^----

$password是用户PW的sql-escaped版本。如果该密码自然包含SQL元字符,则密码将不会与数据库中的密码相等。在DB插入过程中会剥离这些转义,并且您最终会执行类似

的操作
 "Miles O\'Brien" == "Miles O'Brien"

并返回错误的不匹配。