登录php脚本中的Mysqli查询失败:无法成功登录

时间:2015-06-30 21:08:51

标签: php html mysql css

我有一个名为checklogin.php的PhP脚本,该脚本应该查询“电子邮件”。和' motdepasse'来自名为' membres'的表中的值(不是成员),电子邮件的变量类型为varchar (50),motdepasse的变量类型为char (120)

index.html:

<!DOCTYPE html>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii">

    <title> Welcome to Pop </title>
    <link href="normalize.css" rel="stylesheet" />
    <link href="style.css" rel="stylesheet" />
</head>
<body>

<form  action = "checklogin.php"  method="post" name="login_form">
<section class="loginform cf">
<ul>
    <li><label for="usermail">Email</label> <input name="usermail" placeholder="yourname@email.com" required="" type="email" /></li>
</ul>

<ul>
    <li><label for="password">Password</label> <input name="password" placeholder="password" required="" type="password" /></li>
    <li></li>
</ul>
<input   type="submit" name="submit" value="Login"  />

<ul>
</ul>

<p><a accesskey="N" href="Newaccount.html" title="Redirecting ">Create an account</a></p>
</section>
</form>





</body>
</html>

checklogin.php:

<?php 
session_start();
$link = new MySQLi("localhost", "DBusername", "DBpassword", "DBname") ;
error_reporting(E_ALL);
if ( mysqli_connect_error() )
{

    $logmessage = 'MySQL error : ' . mysqli_connect_error() ; 
    die('could not connect to database');
}

$Email = $_POST['Email'];
$Password = $_POST['Password'];
$query= "SELECT Email, motdepasse FROM membres WHERE Email='".$Email."' AND motdepasse='".$Password."' LIMIT 1 ";



if ($result = mysqli_query($link,$query )) 
{

    if( mysqli_num_rows($result) == 1 )
    {

        echo "login successful" ;
     }

     else
     {
          echo "wrong username or password" ;

     }
} 
else
{
    echo' Couldnt select from table. Please check query';
}
?>

我的问题是,尽管与DB的连接没有任何问题,但即使输入的信息与&#39; membres&#39; ,电子邮件和motdepasse列。我之后添加了错误报告功能,但只收到通知。

2 个答案:

答案 0 :(得分:0)

在您的HTML中,有一些名为usermailpassword的输入,但在您的PHP代码中,您尝试获取$_POST['Email']$_POST['Password']。所以只需将这两行更改为:

$Email = $_POST['usermail'];
$Password = $_POST['password'];

答案 1 :(得分:0)

您从

这样的表单发送数据
<input name="usermail" ...

所以变量是usermail但是在你的脚本中你处理$_POST['Email']并且它确实不存在...首先检查你的表单元素的名称并调试你通过顶线发送的内容

var_dump($_POST); exit();

提示:始终根据您的预期测试您所拥有的内容并进行比较