<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "comp4";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT OrderID, id, items FROM orders WHERE id= $user";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$results = $row["OrderID"]. " " . $row["id"]. $row["items"]. "<br>" ;
}
$loop = implode( " ", $items );
echo $loop;
}
?>
So, I have this code and I'm trying to display OrderID, id and items from the user thats logged in $user=whoever's logged in that's in a different part of my code, however I keep getting an error Notice: Trying to get property of non-object in C:\xampp\htdocs\myorders.php on line 35 After looking around, I'm still not quite sure how to fix this. Any help is appreciated