I've got a table of users each with a unique ID. When I try and fetch their ID for the session it returns an array of two IDs for some reason.
So in the following code, $_SESSION['userid'] becomes an array containing two instances of the same ID.
I can't figure out why though...
$_SESSION['userid'] = getUserID($_POST['username']);
function getUserID($username)
{
include 'db.inc.php';
try {
$sql = "SELECT id FROM user WHERE username = '". $username. "'";
$s = $pdo->prepare($sql);
$s->bindValue(':username', $username);
$s->execute();
}
catch (PDOException $e) {
$error = 'Error getting userid for '.$username . '....error: '.$e;
include $_SERVER['DOCUMENT_ROOT']."/database/includes/pages/error.html.php";
exit();
}
$row = $s->fetch();
return $row;
}
SELECT id FROM user WHERE username = :usernamegetUserID()is returning an associative array? Can you post the contents of that array (doprint_r($row))? What are you expecting it to return?