The following error is present when trying to view api.php using localhost:
Fatal error: Assignments can only happen to writable values in /opt/lampp/htdocs/MyApi/api.php on line 27
I had a few errors in my code that I thought would have been contributing to this error (one of which was on line 27), however, still no joy. When I comment out line 27, the error moves on to line 28, and so forth.
I have also tried to change the name of my array to 'job' as it was originally the same name as my table, but didn't seem to fix the issue.
Very inexperienced with PHP (this is actually my first major stab at it), so any help would be much appreciated!
PHP
<?php
define ('DB_HOST', 'localhost');
define ('DB_USER', 'root');
define ('DB_PASS', '');
define ('DB_NAME', 'homeflow_database');
$conn = new mysqli (DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (mysqli_connect_errno()) {
die('Unable to connect to database '. mysqli_connect_error ());
}
$stmt = $conn->prepare ("SELECT maintenance_id, type, property,
more_info, date FROM maintenance;");
$stmt->execute();
$stmt->bind_result($maintenance_id, $type, $property, $more_info, $date);
$job = array();
while($stmt->fetch()) {
$temp = array ();
$temp = ['maintenance_id'] = $maintenance_id;
$temp = ['type'] = $type;
$temp = ['property'] = $property;
$temp = ['more_info'] = $more_info;
$temp = ['date'] = $date;
array_push ($job, $temp);
}
echo json_encode ($job);
Thanks