Ok I'm trying to get my head around PDO to make prepared statements. Here is the code that I am using to test it.
try {
$dbh = new PDO('mysql:host=localhost;dbname=db', $user, $pass);
}catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
//Make the prepared statment
$stmt = $dbh->prepare('SELECT userName,Password FROM members WHERE userName = ? AND Password = ?');
$stmt->execute(array($_POST['username'],$_POST['password']));
//There is a user so check to see if pass is correct.
$row = $stmt->fetchAll();
print_r($row);
echo "<br>HELLOOOO";
echo $row['Password'];
if ($row['Password'] == $_POST['password']) {
//The password is correct so reg. sessions
$_SESSION['user'] = $row['userName'];
$client = md5($_SERVER['HTTP_USER_AGENT']);
header("Location: newslist.php");
}
When the form passes the information I see the print_r($row) array but the if statement does not run. I then added the HELLOOO as a place holder (and to let out stree) tried out echo out the value of $row['Password']. For some reason this is not set even though I can see the array printed out above it.
Can anybody tell me maybe what I am doing wrong?
Thanks
Stephen