简体   繁体   English

PHP登录系统-代码有什么问题?

[英]PHP login system - What's wrong with the code?

I've started a PHP & PDO login system and I'm not sure what's wrong with it, whenever I enter the details in the form (either correctly or incorrectly) it doesn't get to the echo - even if the record exists. 我已经启动了PHPPDO登录系统,但是我不确定它有什么问题,每当我以正确或错误的形式输入详细信息时,即使记录存在,它也不会echo

I've got the registration part of it working, but with the login I'm not sure what's wrong. 我已经完成了注册部分的工作,但是使用登录名我不确定是什么问题。 At the moment I'm currently just trying to get it working so I'm trying to keep it very basic. 目前,我目前正试图使其正常运行,因此我试图使其保持非常基础。

UPDATE: Fixed, was related to the database structure, not the code. 更新:已修复,与数据库结构有关,与代码无关。

You can't include a HTML file, It must be a .php file to run your php code. 您不能包含HTML文件,它必须是.php文件才能运行您的php代码。

Also you need to put your params in quotes. 另外,您需要将参数用引号引起来。

    <?php
include 'login.html';
$conn = new PDO('mysql:host=localhost;dbname=loginreg', 'root', 'dev');
session_start();

    if(isset($_POST['fname'], $_POST['pwd'])){

  $fname = $_POST["fname"];
    $pwd = sha1($_POST["pwd"]);

      $result = $conn->prepare("SELECT * FROM `registered` WHERE `name` = ':name' AND `password` = ':password'");
      $result->bindParam(':name', $fname);
      $result->bindParam(':password', $pwd);
      $result->execute();

      $rows = $result->fetchColumn(0);

        if($rows > 0){
            echo("test");
        }
    }
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM