sto cercando di fare un sistema di login con PDO.
ho aggiunto questo metodo alla classe:
Codice PHP:
public function login($user, $pass) {
$pass = sha1($pass);
$strQuery = "SELECT * FROM user WHERE username='" . $user . "' AND user_pass='" . $pass . "'";
try {
$query = $this->pdo->query($strQuery);
if ($query->fetchColumn() == 1) {
$_SESSION['login_eseguito'] = TRUE;
$_SESSION['user_id'] = $result->user_id;
return TRUE;
} else {
return FALSE;
}
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "
";
die();
}
}
questa la pagina di login:
Codice PHP:
<?php
session_start();
include_once 'config.php';
$obj = new Config();
if ($obj->verifica_sessione()) {
header("location:index.php");
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$login = $obj->login(htmlentities($_POST['username'], ENT_QUOTES), htmlentities($_POST['password'], ENT_QUOTES));
if ($login) {
header("location:area_riservata.php");
} else {
echo 'I dati indicati non sono corretti.';
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Login</title>
</head>
<body>
<?php
include_once 'menu.html';
?>
<table>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<tbody>
<tr>
<td>User:</td>
<td><input type="text" name="username" value="ogadmin" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" value="ogferzap" /></td>
</tr>
<tr>
<td><input type="submit" value="Send" /></td>
</tr>
</form>
</table>
</body>
</html>
quando do invio ottengo sempre questo errore:
Fatal error: Call to a member function fetchColumn() on a non-object in /web/htdocs/www.orangeneration.it/home/og/email/config.php on line 33
la riga 33 è quella dove inizia l'if:
if ($query->fetchColumn() == 1) {
qualche idea??