My problem is im querying to get the id from the row on a login request and set $_SESSION name to the id of that row, but im unsure on how to fetch that properly as my usual method doesn't seem to be working.
So im trying ..
if (isset($_POST['username']) && ($_POST['password'])) {
$username = trim($_POST['username']);
$username = strtolower($username);
$password = trim($_POST['password']);
$password= hash('sha256', $password);
$stmt = $dbh->prepare("SELECT `id` FROM `1_users` WHERE username=? AND password=? LIMIT 1");
$stmt->bindValue(1, $username, PDO::PARAM_STR);
$stmt->bindValue(2, $password, PDO::PARAM_STR);
$stmt->execute();
$row = $stmt->rowCount();
if ($row) {
// Match
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
$_SESSION['user'] = $result['id'];
$_SESSION['logged_in'] = TRUE;
$_SESSION['ip'] = hash('sha1', "{$_SERVER['REMOTE_ADDR']}");
echo $result['id'];
//header ("location: staff.php");
}
unfortunatly $result['id']
is erroring as a undefinded index..
and echo $result['id'];
is not outputting anything. but I know the row was found so what am I doing wrong when trying to get the id of that row into a variable?