登录页面和注册页面连接

时间:2018-06-08 06:05:38

标签: html mysql mysqli

各位程序员下午好, 我是一个新的PHP代码,在上一个问题我询问注册和登录页面问题之间的关系。按照说明申请后,问题解决了。现在我再试一次,选择查询不想工作。虽然我输入了正确的密码,但它直接登录失败。我尝试从另一个数据库工作,但从这个表,它不想工作。另一件事是每当我启动xampp它显示键_缓冲区。这是否使我的查询无效。下面我附上我的代码,希望得到开发人员的帮助。非常感谢。

Register Php

<?php 
session_start();
$_SESSION['message']=''; 
$mysqli=new MySQLi('127.0.0.1','root','','accounts');



if(isset($_POST['login'])) {
    $username = $mysqli->real_escape_string($_POST['username']);
        $password = md5($_POST['password']);
         $sql="SELECT * FROM users WHERE username='$username' AND password='$password' LIMIT 1;";
      $result = mysqli_query($mysqli,$sql);

        if(mysqli_num_rows($result) > 0){
              $row = mysqli_fetch_array($result);

        if (($row['username']=='sithi')&&($row['password']=='202cb962ac59075b964b07152d234b70')){
              $_SESSION['user_type'] = $row;
              $_SESSION['password'] = $row;
              $_SESSION['message'] =  "Registration successful!";
    header("location:myresuming.html");exit();
        }
    else{

              $_SESSION['username'] = $row['username'];
              $_SESSION['profile'] = $row['profile'];
              $_SESSION['message'] =  "Registration successful!";
    header("location:Welcome.php");exit();
    }
        }
    else{
        $_SESSION['message'] = "Login Failed!"; 
    }

}



?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>form in Design</title>
<link rel="stylesheet" type="text/css" href="mystyle.css" />
<link rel="stylesheet" type="text/css" href="form.css" />
</head>
<body>
<div class="container"><?=$_SESSION['message']?>
<img src="5.jpg" />
<form class="form" action="" method="post" enctype="multipart/form-data" autocomplete="off">
      <div class="alert alert-error"></div>
      <input type="text" placeholder="User Name" name="username" required />
      <input type="password" placeholder="Password" name="password" autocomplete="new-password" required />
 <input type="submit" name="login" value="login" class="btn-login" />

</form>
</div>
</body>
</html>

登录页面

<?php
session_start();
$_SESSION['message'] = '';
$mysqli=new MySQLi('127.0.0.1','root','','learning_malaysia');
 if(isset($_POST['login'])) {
    $username = $mysqli->real_escape_string($_POST['username']);
        $password = md5($_POST['password']);
         $sql="SELECT*FROM tutor_register WHERE username ='$username' AND password ='$password'";
      $result = mysqli_query($mysqli,$sql) or die(mysql_error());
      $row = mysqli_num_rows ($result);

        if(mysqli_num_rows($result) > 0){
              $row = mysqli_fetch_array($result);
              $_SESSION['username'] =  $username;
    header("location:class.php");
    }

    else{
        $_SESSION['message'] = "Login Failed!"; 

        }
}
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?=$_SESSION['message']?>
<form class="form" action="" method="post" enctype="multipart/form-data" autocomplete="off">
      <div class="alert alert-error"></div>
      <input type="text" placeholder="User Name" name="username" required />
      <input type="password" placeholder="Password" name="password" autocomplete="new-password" required />
 <input type="submit" name="login" value="login" class="btn-login" />

</body>
</html>

0 个答案:

没有答案
相关问题