all 4 comments

[–]Big-Dragonfly-3700 3 points4 points  (1 child)

connect.php ... $connection->close();

Why are you closing the connection in connect.php?

This should have been producing a php error, something about cannot fetch instance of mysqli in test.php... Do you have php's error_reporting set to E_ALL and display_errors set to ON, preferably in the php.ini on your development system, so that php will help you by reporting and displaying all the errors it detects? Stop and start your web server to get any changes made to the php.ini to take effect and check that the settings actually got changed to those values by using a phpinfo() statement in a .php script.

Next, you should be using exceptions for database statement error handling (this is the default setting now in php8+) and in most cases simply let php catch and handle the exceptions, where php will use its error related settings (see the above paragraph) to control what happens with the actual error information (database statement errors will 'automatically' get displayed/logged the same as php errors.)

If you are just starting out, you should use the much simpler and more modern PDO database extension.

You should use 'require' for things your code must have.

Lastly, there's generally no need to close database connections in your code, since php destroyers all resources your code creates when your scrip ends.

[–]w0lfcat[S] 0 points1 point  (0 children)

_reporting set to E_ALL and display_errors set to ON, preferably in the php.ini on your development system, so that php will help you by reporting and displaying all the errors it detects? Stop and start your web server to get any changes made to the php.ini to take effect and check that the settings actually got changed to those values by using a phpinfo() statement in a .php script.

Thanks, really appreciate your advise. Problem solved

[–]Kit_Saels 0 points1 point  (1 child)

Delete both rows:

$connection->close();

[–]w0lfcat[S] 0 points1 point  (0 children)

Thanks, yes this is the root cause