dimanche 22 novembre 2015

PHP and SQlite: Login

I need to do a Login form with PHP an SQlite. Registration works, and I can select all created users and echo them. But if I want to catch only one user, which name I get by $_POST, I get the following error:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1 no such column: <username I got by $_POST>

My code is this:

$db = new PDO('sqlite:mysqlitedb.db');
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

$username = $_POST['username'];
$password = md5($_POST['password']);

$sql = "SELECT * FROM users WHERE user_name = $username";
$result = $db->query($sql);
while ($row = $result->fetch()){
   echo $row['user_name'] . '<br />';
}

What's wrong here?

Aucun commentaire:

Enregistrer un commentaire