i got the error for line while($array[] = $query->fetch_object());
<?php
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection to database failed: " . $conn->connect_error);
}
echo "";
$query = mysqli->query("SELECT * FROM 'Contracts'");
while($array[] = $query->fetch_object());
array_pop($array);
print_r_html($array);
?>
I am not able to understand why??? please help! thank you
There are 2 errors here.
First for mysqli
. It is being treated as a constant.
$query = mysqli->query
it should read as
$query = $conn->query
and using $conn
as your variable.
Then you're using single quotes around your table rather than ticks or none at all.
$query = $conn->query("SELECT * FROM `Contracts`");
or
$query = $conn->query("SELECT * FROM Contracts");
References: