用PHP和mysql登录 [英] Login with PHP and mysql

查看:51
本文介绍了用PHP和mysql登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的登录脚本有问题.当我按下登录"按钮时,它将始终显示它是一个无效密码,即使不是. Login.php在我的屏幕上显示以下内容:

I'm having an issue with my login script. When I press the 'login' button, it will always display that it's an invalid password, even though it's not. Login.php prints the following into my screen:

密码错误.

);}}?>

这是
login.php

<?
    $con = mysqli_connect("localhost","root","","formularios");
    if ( mysqli_connect_errno() ){
      echo "There was a problem establishing a connection with the database: " . mysqli_connect_error();
      }
    session_start();
        if ( isset($_POST['email']) ){

            $email = stripslashes($_REQUEST['email']); 
            $email = mysqli_real_escape_string($con,$email);
            $password = stripslashes($_REQUEST['password']);
            $password = mysqli_real_escape_string($con,$password);
            $query = "SELECT * FROM `usuarios` WHERE email='$email' and password='".$password."'";
            $result = mysqli_query($con,$query) or die(mysql_error());
            $rows = mysqli_num_rows($result);

            if($rows==1){
                $_SESSION['email'] = $email;
                header("Location: home.html");
            } else{
                echo utf8_decode("<div class='form'><h3>Wrong password.</h3></div>");
            }
        }
?>

这是我的主页, index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Formularios</title>
    <meta charset="UTF-8">
</head>
<body>  
    <div class="limiter">
        <div class="container-login100">
            <div class="wrap-login100 p-l-55 p-r-55 p-t-65 p-b-50">
                <form class="login100-form validate-form" action="cdb.php">
                    <span class="login100-form-title p-b-33">
                        <img src="images/2.png" height="60px" width="auto" name="Logo">
                    </span>
                    <div class="wrap-input100 validate-input" data-validate = "Se requiere un correo electrónico válido, ej: nombre.apellido@iesahn.com">
                        <input class="input100" type="text" name="email" id="email" placeholder="Correo Electrónico">
                        <span class="focus-input100-1"></span>
                        <span class="focus-input100-2"></span>
                    </div>
                    <div class="wrap-input100 rs1 validate-input" data-validate="Es obligatorio poner tu contraseña">
                        <input class="input100" type="password" id="password" name="password" placeholder="Contraseña">
                        <span class="focus-input100-1"></span>
                        <span class="focus-input100-2"></span>
                    </div>
                    <div class="container-login100-form-btn m-t-20">
                        <button class="login100-form-btn">
                            Iniciar Sesión
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <script src="vendor/jquery/jquery-3.2.1.min.js"></script>
    <script src="vendor/animsition/js/animsition.min.js"></script>
    <script src="vendor/bootstrap/js/popper.js"></script>
    <script src="vendor/bootstrap/js/bootstrap.min.js"></script>
    <script src="vendor/select2/select2.min.js"></script>
    <script src="vendor/daterangepicker/moment.min.js"></script>
    <script src="vendor/daterangepicker/daterangepicker.js"></script>
    <script src="vendor/countdowntime/countdowntime.js"></script>
    <script src="js/main.js"></script>
</body>
</html>

我在哪里弄糟?我按照他们的语法浏览了PHP网站,但是仍然无法正常工作.我仍然是一个初学者,我正在尝试开发一个基本的登录/注销站点,该站点将允许员工访问我为内部使用而开发的在线Web配方. 我已经准备好所有东西,但这使我受挫. 我知道我应该使用PDO而不是mysqli,但是老板们不赞成这样做.他们对PDO不熟悉,他们想在需要的时候进行修改.有任何解决方法吗?

Where am I screwing up? I went through the PHP website, following their syntax, but still, it's not working. I'm still a begginner, and I'm trying to develop a basic log-in / log-out site that will allow employees access online web formularies that I developed for our internal use. I have everything set up, but this is holding me off. I know I should be using PDO instead of mysqli, but my bosses wouldn't approve this. They're not familiar with PDO and they want to modify things whenever they feel like it. Any pointers to fix this?

推荐答案

此行中可能存在问题:

     $query = "SELECT * FROM `usuarios` WHERE email='$email' and password='".$password."'"

您缺少串联运算符(我的意思是在$ email前加句号)尝试修复它.那可能行得通.并且还将您的代码与准备好的语句集成在一起,以防止sql注入.

You are missing concatenation operator(I mean a full stop before $email) Try fixing it. That might work. And also integrate ur code with prepared statement to prevent sql injection.

如果正在打印该错误,则机器可能未将代码解释为php代码.在login.php文件末尾查找语法错误

If that error is being printed, the machine might not be interpreting the code as a php code. Look for syntax errors at the end of login.php file

这篇关于用PHP和mysql登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆