密码和用户名匹配错误

时间:2016-12-14 16:32:17

标签: php mysql

当我登录时,即使密码和用户名都是正确的,也会出现错误。

它保持显示"用户名/密码组合不正确"。

用户名和密码已激活且已存在。请帮帮我:(

的login.php

<?php
 session_start();

 //connect to database
 $db = mysqli_connect("localhost","root","","carrentalsystem");

 if (isset($_POST['login_btn'])) {

     $Name = mysql_real_escape_string($_POST['Name']);
     $password = mysql_real_escape_string($_POST['password']);

     $password = md5($password); 
     $sql = "SELECT * FROM customer WHERE Name='$Name' AND password='$password'";
     $result = mysqli_query($db,$sql);

     if (mysqli_num_rows($result) == 1){
         $_SESSION['message']= "You are now logged in";
         $_SESSION['Name']= $Name;
         header("location: home.php");
         }else{
             $_SESSION['message']= "Username/password combination  incorrect";
         }
 }?>

register.php

<?php
 session_start();

 //connect to database
 $db = mysqli_connect("localhost","root","","carrentalsystem");

 if (isset($_POST['register_btn'])) {

     $CustIC = mysql_real_escape_string($_POST['CustIC']);
     $Name = mysql_real_escape_string($_POST['Name']);
     $DOB = mysql_real_escape_string($_POST['DOBNo']);
     $Address = mysql_real_escape_string($_POST['Address']);
     $EmailID = mysql_real_escape_string($_POST['EmailID']);
     $password = mysql_real_escape_string($_POST['password']);
     $rePassword = mysql_real_escape_string($_POST['rePassword']);

     if ($password == $rePassword) {
         //create user
         $password = md5($rePassword);
         $sql = "INSERT INTO customer(CustIC, Name, DOBNo, Address, EmailID, password, rePassword) VALUES('$CustIC', '$Name', '$DOBNo', '$Address',  '$EmailID', '$password', '$rePassword')";
         mysqli_query($db,$sql);
         $_SESSION['message'] = "You are now logged in";
         $_SESSION['Name'] = $Name;
         header("location: login.php");
     }else{
         $_SESSION['message'] = "The two passwords do not match";
     }
 }?>

0 个答案:

没有答案