Fatal error: Call to a member function query() on a non-object in comments/comments.inc.php on line 10
My php code looks like this:
<?php
function setComments($conn) {
if(isset($_POST['commentSubmit'])) {
$uid = $_POST['uid'];
$date = $_POST['date'];
$message = $_POST['message'];
$sql = "INSERT INTO comments (uid, date, message) VALUES ('$uid','$date','$message')";
$result = $conn->query($sql);
}
}
I really don't understand how to fix this problem, as I'm trying to learn php. Any help is welcome, thanks.
The page with this code is an include for another page.
The other include i have has its code that looks like this:
<?php
$conn = mysqli_connect('localhost','username','password','database');
if (!$conn) {
die("Connection failed: ".mysqli_connect_error());
}
both of these includes are called on a main page called index.php.