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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.