-1

I am trying to create simple log-in function where I am using PHP and SQLite to make it work but every time I click log-in I get "Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in G:\wwwroot\login.php:3 Stack trace: #0 G:\wwwroot\login.php(3): PDO->__construct('sqlite:G:/wwwro...') #1 {main} thrown in G:\wwwroot\login.php on line 3" am I doing something wrong any advice will be GREAT :).

I have log-in code and saved it as index.php

<html>
    <body>
        <form action="login.php" method="POST">
        <p>Username</p><input type ="text" name="user"/>
        <p>password</p><input type="password" name="pass"/>
        <br />
        <input type="submit" value="login"/>
        </form>
    </body>
</html>

I have another php called login.php and will be activated when the user clicks login button

<?php
    $dir = 'sqlite:G:/wwwroot/SQLite/user_information.db';
    $dbh = new PDO($dir) or die ("cannot open");

    $myusername = $_POST['user'];
    $mypassword = $_POST['pass'];

    $myusername = stripslashes($myusername);
    $mypassword = stripslashes ($mypassword);

    $query = "SELECT * FROM user_information WHERE username='$myusername' AND password='$mypassword'";
    $result = mysql_query($query);
    $count = mysql_num_rows($result);

    if($count==1){
    echo'worked';
    }

?>

And at last I have user_information.db where I downloaded sqlite3 and using cmd program to create the database.

G:\wwwroot\SQLite>sqlite3 user_information.db
SQLite version 3.8.4.3 2014-04-03 16:53:12
Enter ".help" for usage hints.
sqlite> create table user_info(username varchar(20), password varchar(20));
sqlite> insert into user_info values('WESTKINz','password');
sqlite> insert into user_info values('LAME','123456');
BenMorel
  • 34,448
  • 50
  • 182
  • 322
WESTKINz
  • 257
  • 1
  • 6
  • 18

1 Answers1

0

Like the error says, it appears your server does not have the driver installed/loaded.

Check your phpinfo to see if you have the driver is registered. Make sure the sqlite extensions are uncommented in your php.ini. On Windows the php.ini file will probably be in C:\Windows\System32\PHP\php.ini. Phpinfo() should tell you where the config is located. See this post.

Also, a similar post with MySQL

Joshua I. James
  • 143
  • 1
  • 8
  • Did you see [this](http://stackoverflow.com/a/2756950/3523577) comment, specifically: _PDO works only when I use the DSN prefix "sqlite2" which is not very surprising, since phpinfo() only lists the driver "sqlite2" under the section "PDO"_ What extensions does your phpinfo list under PDO? – Joshua I. James Apr 11 '14 at 12:27
  • don't worry about it, i ditch this project and doing something else but thanks :) – WESTKINz Apr 11 '14 at 12:35