I've had a look round on google and a couple of other sites, but I can't figure out why this isn't working.
I'm working on a uni assignment, and run the following code:
$db = connect();
$testname = 'chunk';
try {
$stmt = $db->prepare('SELECT * FROM TreasureHunt.Player WHERE name = ?');
$stmt->execute(array($testname));
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
}
catch (PDOException $e) {
print "Error checking login: " . $e->getMessage();
}
$count = $stmt->rowCount();
echo 'Row count: ', $count, '<br>';
var_dump($result);
echo '<br>Result: ', $result['name'], ' pw: ', $result["password"], '<br>';
print_r($result);
However this results in the following errorm:
Notice: Undefined index: name in /.automount/net/ufiler2/u2/cs3/dbes2376/lib/html/th/index.php on line 30
Now I know that means, that in my $result variable the index 'name' must not exist. But this confuses me because it does exist, checked by looking in: var_dump($result) var_dump($result) gives me:
array(1) { [0]=> array(5) { ["name"]=> string(5) "chunk" ["password"]=> string(7) "truffle" ["pw_salt"]=> string(8) "g#m#g#m#" ["gender"]=> string(1) "m" ["addr"]=> string(10) "Goon Docks" } }
and print_r($result) gives me:
Array ( [0] => Array ( [name] => chunk [password] => truffle [pw_salt] => g#m#g#m# [gender] => m [addr] => Goon Docks ) )
So why can I not refer to them as $result['name'] ? Or how do I actually refer to it?
Thanks. Sorry if this is a basic question.