Question

I am creating a fairly basic login form using PDO for the first time. I'm pretty new to PDO and can't figure this one out.

My code is:

require_once('setEnv.php');
require_once( 'functions/functions.php' );

$username = $_REQUEST['username'];
$password = $_REQUEST['password'];

$db = classes_pdoDB::getConnection();
$query = "SELECT password, salt
    FROM user
    WHERE username=:username";
$stmt = $db->prepare($query);
$stmt->execute(array(':username' => $username));

while($asd = $stmt->fetchObject()){

echo $asd->username;

}

and the error message I am getting is

  Notice: Undefined property: stdClass::$username in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_v010224/public_html/project/executeLog.php on line 18

Thanks!

Was it helpful?

Solution

$query = "SELECT password, salt

You are not selecting the username, so the result doesn't have one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top