【发布时间】:2016-12-14 05:59:03
【问题描述】:
当我登录时,我使用的是 mysql.user,但如果用户有密码,我将无法登录。如果我使用任何用户使用密码登录,则页面无法登录到其他 php。
登录时输入的用户将用于连接数据库。
<?php session_start(); ?>
<!DOCTYPE HTML>
<html>
<head>
<title>Log in</title>
<meta charset="UTF-8" />
<link rel="stylesheet" type="text/css" href="css/reset.css">
<link rel="stylesheet" type="text/css" href="css/structure.css">
<?php include('connection.php'); ?>
</head>
<body>
<form class="box login" method="post">
<fieldset class="boxBody">
<label>Username</label>
<input type="text" tabindex="1" placeholder="Username" required name="username" id="username">
<label><label class="rLink" tabindex="5">Optional</label>Password</label>
<input type="password" tabindex="2" placeholder="Password" name="password" id="password" >
</fieldset>
<footer>
<input type="submit" class="btnLogin" value="Login" tabindex="4" name="sent">
</footer>
</form>
<?php
if (isset($_POST['sent'])) {
$servername = "localhost";
$username = ($_POST['username']);
$password = ($_POST['password']);
$message="";
// Create connection
$result = $conn->query("SELECT user FROM mysql.user where user='$username' and password='$password'");
if ($result->num_rows > 0) {
$_SESSION["uname"] = "$username";
$_SESSION["pass"] = "$password";
echo '<script type="text/javascript">alert(<?php echo "Success!";?>)</script>';
header("location: main.php");
} else {
$message = "Successfuly entered! hi! $username";
echo '<script type="text/javascript">alert(<?php echo "$message";?>)</script>';
}
}
// Check connection
?>
</body>
</html>
【问题讨论】:
-
你可以设置它,也可以登录,你不能从一个散列中得到非散列值。您可以拨打
SET PASSWORD FOR 'jeffrey'@'localhost' = PASSWORD('cleartext password'); -
我想你想在找到用户时“提醒”或者如果你不这样做:` if ($result->num_rows > 0){ $_SESSION["uname"] = "$用户名”; $_SESSION["pass"] = "$password"; echo ''; header("位置:main.php"); } else { $message = "成功输入!你好!$username"; echo '';} } ` 您忘记了“alert”参数的引号。
-
@BenoitNgô 我的 select 查询密码不起作用,
标签: javascript php mysql sql web