我在登录功能时遇到了一些麻烦。我一直在寻找几个小时,我无法找到任何问题。我希望你们能帮助我。 我想获取用户的登录名并检查它是否存在于我的数据库中。问题是它不断返回我:“密码可能不正确!”。 我试过一个“echo($ count)”,它不会返回任何东西。 “echo($ result)”是同样的东西。PHP登录和MySql查询
我几乎失去了正确的,我不明白为什么这不工作...
PS:我是法国人,所以你可能会看到一些法语单词。
这里是我的登录表单:
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Applications</title>
<!--Chargement des feuilles de style-->
<link rel="stylesheet" type="text/css" href="./css/style.css" />
<link rel="stylesheet" type="text/css" href="./css/styleLogin.css" />
<script src="./js/login/modernizr.custom.63321.js"></script>
</head>
<body>
<div class="container">
<header></header>
<section class="main">
<form class="form-2" id="loginForm" action="./controller/checkLogin.php" method="post">
<h1><span class="log-in">Se connecter</span></h1>
<p class="float">
<label for="loginLabel"><i class="icon-user"></i>Nom d'utilisateur</label>
<input type="text" name="login" id="login">
</p>
<p class="float">
<label for="passwordLabel"><i class="icon-lock"></i>Mot de passe</label>
<input type="password" name="password" class="showpassword" id="password">
</p>
<p class="clearfix">
<input type="submit" name="submit" value="Se connecter">
<input type="button" name="submitVisit" value="Accès utilisateur">
</p>
</form>
</section>
</div>
</body>
这是我的checkLogin.php:
<?php
session_start();
try {
$bdd = new PDO('mysql:host=localhost;dbname=stage','root','');
}
catch (Exception $e){ //en cas d'erreur de connexion, afficher le message
die('Erreur : '.$e->getMessage());
}
if(isset($_POST['submit'])){
// username and password sent from form
$login = $_POST['login'];
$pass = $_POST['password'];
$qry = "SELECT login FROM users WHERE login = 'admin'";
$result = mysql_query($qry);
// Mysql_num_row is counting table row
$count = mysql_num_rows($result);
if($count == 0){
die("Password was probably incorrect!");
}
// If result matched $myusername and $mypassword, table row must be 1 row
elseif($count == 1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
$_SESSION['login'] = $login;
header("location: ./login_success.php");
}
else {
echo "Wrong Username or Password";
}
}
mysql_close($bdd);
?>
我想这对夫妻登录:行政/管理。
预先感谢您。
你为什么使用PDO然后mysql _ *? – Class 2013-04-11 07:35:08
混淆:S其中是mysql_select_db,为什么混合使用PDO和mysql,而且mysql_query已被弃用! – Vimalnath 2013-04-11 07:37:22
OMG你的代码是一种混乱..你正在使用mysql_ *与pdo和登录没有使用id和密码和登录每个用户提交,甚至没有验证输入.. – 2013-04-11 07:41:59