Need you help guys i got this error. 1st loop successfully inserted 1st record Dont know why on the 2nd loop of do while it display this error.
PHP Notice – yii\base\ErrorException
Trying to get property of non-object
"$studid = $user->studid;" <-- Highlighted error
Need to query the user table to check the username and get the studid(student ID No. FK)
User Table (userid(pk), username, password, studid(fk))
$model->recipient // client inputted 3 username seperated by comma(glads,venus,nico) in the textInput
//parse the usernames form textInput
$userrecipient = explode(",", $model->recipient); //saved as an array[glads,venus,nico]
$index = 0;
$user = new User();
$receiver = new Manage();
do {
$user = User::find()
->where(['username' => $userrecipient[$index]])
->one();// <-- seems on 2nd loop this command is not executing?
//insert to manage table
$studid = $user->studid;//<-- highlighted error "Trying to get property of non-object" on the 2nd insertion
$receiver->studid = $studid ; // Student receiver
$receiver->msgid = $msgid;
$receiver->msg_statusid = 2; // 2= received by default
$receiver->date = date('Y-m-d H:i:s');
$receiver->discard = 0;
$receiver->unread = 0;
$receiver->bounced = 0;
$receiver->save();
$index++;
} while ($index < count($userrecipient));