简体   繁体   中英

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.

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.

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");
        }
    }
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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