Attempting to try and join my table called 'UserCaseMessages' with my other table called 'Comments' using this exact sql command in php:
$sql = "
SELECT UserCaseMessages.DefendantID, Comments.CommentID
FROM UserCaseMessages
INNER JOIN Comments
ON UserCaseMessages.DefendantID = Comments.SenderID
";
$result = $conn->query($sql);
if ($result->num_rows > 0) // ERROR GETS THROWN ON THIS LINE {
}
Here is the connection part to my database (which occurs prior to the query):
$servername = "localhost";
$username = "username";
$password = "password";
// Get the username from the post
$userUsername = $_POST['string'];
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
I get the following error:
PHP Notice: Trying to get property of non-object
I cannot figure out what I am doing wrong here!! Everything is spelled correctly and a checked and checked for any syntax errors and I can't find any, however I am new to this particular method. Please help!