Jump to content

PHP PDO login help required.


9tglhe6nwj

Recommended Posts

Okay, so below I have posted my code, the problem I am having is not knowing how PDO works that well. So what I have attempted to do here is use SQL to check if the user and password are correct, but I'm not sure how to carry on. I realize I have to determine if the database found the matching password and/or username but I have no idea how, any help will be much appreciated.

<html>
    <head>
        <title>Database login</title>
        <?php
        if (isset($_POST['submit'])) {
            print_r($_POST);
            $password = md5($_POST['password']);
            echo'<p>'.$password.'</p>';
            $username = ($_POST['username']);
            echo'<p>'.$username.'</p>';
        }
        ?>
    </head>
    <body>
        <?php 
        $db = new PDO('sqlite:login.sqlite');
        $login = 'SELECT * FROM login
        WHERE userid="'.$username.'"
        AND password="'.$password.'";';
        echo'<p>'.$login.'</p>';
        $attempt = $db->query($login);
        ?>
            <form method="post" action="Db_login.php">
            <p>Username:<br /><input type="text" name="username" /> </p>
            <p>Password:<br /><input type="password" name="password" /></p>
            <p><input type="submit" name="submit" value="Log In!" /></p>
    </body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/228623-php-pdo-login-help-required/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.