2015-07-28 135 views
-2

虽然同样的概念正在其他形式的登录功能,我无法这样做。帮我登录并注册。无法执行此操作。这里是登录和注册表格以及hlater login.php页面的代码,用于登录和注册数据库。所有细节都在代码中。并善意报告错误和进一步的修改要求。在此先感谢:无法登录使用PHP

<!DOCTYPE html> 
<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6 lt8"> <![endif]--> 
<!--[if IE 7 ]> <html lang="en" class="no-js ie7 lt8"> <![endif]--> 
<!--[if IE 8 ]> <html lang="en" class="no-js ie8 lt8"> <![endif]--> 
<!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]--> 
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]--> 
    <head> 
     <meta charset="UTF-8" /> 
     <!-- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> --> 
     <title>Login and Registration Form T & P Cell</title> 
     <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
     <meta name="description" content="Login and Registration Form with HTML5 and CSS3" /> 
     <meta name="keywords" content="html5, css3, form, switch, animation, :target, pseudo-class" /> 
     <meta name="author" content="Codrops" /> 
     <link rel="shortcut icon" href="../favicon.ico"> 
     <link rel="stylesheet" type="text/css" href="css/demo.css" /> 
     <link rel="stylesheet" type="text/css" href="css/style.css" /> 
     <link rel="stylesheet" type="text/css" href="css/animate-custom.css" /> 
    </head> 
    <body> 
     <div class="container"> 
      <!-- Codrops top bar --> 
      <div class="codrops-top"> 

       <span class="right"> 

       </span> 

      </div><!--/ Codrops top bar --> 

      <section style=" height: 480px">     
       <div id="container_demo" > 

        <a class="hiddenanchor" id="toregister"></a> 
        <a class="hiddenanchor" id="tologin"></a> 
        <div id="wrapper"> 
         <div id="login" class="animate form" style=" height: 270px"> 
          <form action="login.php" method="POST" autocomplete="on"> 
           <h1>Log in</h1> 
           <p> 
            <label for="username" class="uname" data-icon="u" > Your email or username </label> 
            <input id="username" name="username" required="required" type="text" /> 
           </p> 
           <p> 
            <label for="password" class="youpasswd" data-icon="p"> Your password </label> 
            <input id="password" name="password" required="required" type="password" /> 
           </p> 
           <p class="keeplogin"> 
            <input type="checkbox" name="loginkeeping" id="loginkeeping" value="loginkeeping" /> 
            <label for="loginkeeping">Keep me logged in</label> 
           </p> 
                  <p class="login button" style="float: left"> 

         Not a member?   <a href="#toregister" class="to_register" > Join Us                          </a> 
           </p> 
           <p class="login button"> 
            <input type="submit" value="Login" /> 
           </p> 

          </form> 
         </div> 

         <div id="register" class="animate form" style=" height: 400px"> 
          <form action="mysuperscript.php" autocomplete="on"> 
           <h1> Sign up </h1> 
           <p> 
            <label for="usernamesignup" class="uname" data-icon="u"> Full name</label> 
            <input id="usernamesignup" name="usernamesignup" required="required" type="text" /> 
           </p> 
           <p> 
            <label for="emailsignup" class="youmail" data-icon="e" > Your email</label> 
            <input id="emailsignup" name="emailsignup" required="required" type="email" /> 
           </p> 
           <p> 
            <label for="passwordsignup" class="youpasswd" data-icon="p">Your password </label> 
            <input id="passwordsignup" name="passwordsignup" required="required" type="password" /> 
           </p> 



           <p> 
            <label for="passwordsignup_confirm" class="youpasswd" data-icon="p">Please confirm your password </label> 
            <input id="passwordsignup_confirm" name="passwordsignup_confirm" required="required" type="password"/> 
           </p> 

           <p class="login button" style="float: left"> 
           Already a member ? 
            <a href="#tologin" class="to_register"> Go and log in </a> 
           </p> 
           <p class="signin button"> 
            <input type="submit" value="Sign up"/> 
           </p> 

          </form> 
         </div> 

        </div> 
       </div> 
      </section> 
     </div> 
    </body> 
</html> 




     <?php 
    session_start(); // Starting Session 
    $error = ''; // Variable To Store Error Message 
    if (isset($_POST['submit'])) { 
     echo "string6"; 
     if (empty($_POST['username']) || empty($_POST['password'])) { 
      echo "gh"; 
      $error = "Username or Password is invalid"; 
     } else { 
      echo "asdfgh"; 
      // Define $username and $password 
      $username = $_POST['username']; 
      $password = $_POST['password']; 
      // Establishing Connection with Server by passing server_name, user_id and password as a parameter 
      $connection = mysqli_connect("localhost", "root", ""); 
      // To protect MySQL injection for Security purpose 
      $username = stripslashes($username); 
      $password = stripslashes($password); 
      $username = mysqli_real_escape_string($username); 
      $password = mysqli_real_escape_string($password); 
      // Selecting Database 
      $db   = mysqli_select_db("tandp_db", $connection); 
      // SQL query to fetch information of registerd users and finds user match. 
      $query  = mysqli_query("select * from login where password='$password' AND username='$username'", $connection); 
      $rows  = mysqli_num_rows($query); 
      if ($rows == 1) { 
       $_SESSION['login_user'] = $username; // Initializing Session 
       header("location:login.html"); // Redirecting To Other Page 
      } else { 
       $error = "Username or Password is invalid"; 
      } 
      mysqli_close($connection); // Closing Connection 
     } 
    } 
    ?> 
+2

什么是错误? –

+0

可能'标题已发送'? – DevDonkey

+0

其实.. PHP代码不工作...意味着无法执行任何PHP操作 –

回答

0
在下面的代码放在你的脚本

,你正在检查这一点:如果(isset($ _ POST [“提交”])),所以在登录表单给名称提交按钮: <input type="submit" name="submit" value="Login" />