简体   繁体   中英

Notice: Undefined property: stdClass::$username when using PDO to login

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!

 $query = "SELECT password, salt 

您没有选择username ,所以结果没有一个。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM