For some reason, I keep getting this error.
Here is the code:
<?
if(isset($_POST['reciever'])){;
$aan = htmlspecialchars(filter_var($_POST['reciever'], FILTER_SANITIZE_STRING));
$stmt2 = $mysqli->prepare("SELECT `id` FROM `gebruikers` WHERE `naam` = ? ");
$stmt2->bind_param("s", $aan);
$stmt2->execute();
$kpey = $stmt2->get_result()->fetch_object();
$userid = htmlspecialchars(filter_var($_SESSION['user_id'], FILTER_VALIDATE_INT));
$stmt3 = $mysqli->prepare("SELECT `naam` FROM `gebruikers` WHERE `id` = ? ");
$stmt3->bind_param("i", $userid);
$stmt3->execute();
$kpeya = $stmt3->get_result();
$aan2 = $kpey->id;
$bericht = htmlspecialchars(filter_input(INPUT_POST, 'message', FILTER_SANITIZE_STRING));
$date = date("Y-m-d G:i:s");
$userid = htmlspecialchars(filter_var($_SESSION['user_id'], FILTER_VALIDATE_INT));
$stmt1 = $mysqli->prepare("INSERT INTO msg (msg_van, msg_aan, msg_txt, msg_date)
VALUES (?, ?, ? , ? )");
$stmt1->bind_param('ssss', $userid, $aan2, $bericht,$date);
$stmt1->execute();
echo "Message has been send!"; ?>
Backend log:
PHP Notice: Trying to get property of non-object
This error is at line 69 which is: $aan2 = $kpey->id; in this example.