So far, the only indication that any of your php code is running at all, is the fatal runtime error you mentioned in reply #2, which is for some code other than the current problem code.
Back to the php error_reporting/display_errors settings. How have you obtained and installed your web server/php? If you used one of the all-in-once packages, the control panel for it should have a way of editing the php.ini. Otherwise, you can find where the php.ini that php is using is, by creating a .php script file with the following in it, then request the file through your web server using your browser -
[php]<?php
phpinfo();
?>[/php]
There will be a Loaded Configuration File line in the resulting output that shows the path and filename of the php.ini that you would need to edit with the error_reporting/display_errors settings. The output from the phpinfo() statement also shows what the error_reporting/display_errors settings are. To insure that any changes you make to the php.ini take effect, you need to restart your web server and check using a phpinfo() statement that the changes actually have taken effect.
While you are making changes to the php.ini, find what the output_buffering setting is, and set it to OFF, it if is anything other than OFF. This setting hides problems and hides output from your code and php errors, making it harder to write and test code. The only time you should use output buffering is if you need to buffer output and this setting should normally be off.
This should get you to the point where php and/or your code will give you an indication of why it isn’t running on your server. As to why the code you are finding in a tutorial doesn’t work for you, there can be typos, differences in php configuration, and differences in php versions that would allow code to work on one server but not another. This is why you must get php to help you when you are leaning, developing, and debugging code, by having the error_reporting/display_errors settings set as suggested.
You also need to ALWAYS have error handling for statements that can fail, in this case the database connection and query statements, and you shouldn’t output the actual error messages when running code on a live/public server, as this gives hackers useful information. The easiest way of adding error handling, that doesn’t involve adding conditional logic for each statement (Keep It Simple - KISS), is to use exceptions and let php catch any exceptions. This also addresses not outputting the actual error information when on a live serve, since php will use the error_reporting/display_errors/log_errors settings to control what happens with the actual error information. When on a live server, you would set display_errors to OFF and set log_errors to ON. To enable exceptions for the mysqli statements, add the following two lines of code before the database connection code, and remove the code trying to detect the connection error (which may not be working correctly anyway) -
[php]
// note: the variable $driver in these two lines of code can be any chosen name and is not tied to any variable name you are using in the rest of your database code
$driver = new mysqli_driver();
$driver->report_mode = MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT; // MYSQLI_REPORT_ALL <- w/index checking; w/o index checking -> MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT;[/php]
BTW - the code in reply #2 is not selecting a database, so after you get the error_reporting/display_errors settings set as suggested and enable exceptions, you should be getting some useful error output when the code runs. Also, the $conn->connect_error doesn’t work in older php versions and the posted code may not be detecting a connection error at all, which may account for the symptoms you are getting, but this problem will go away if you switch to use exceptions and remove the code trying to use $conn->connect_error. What php version are you using?
Lastly, the php mysqli extension is the not written the best (the problem with the $conn->connect_error not working in some versions of php is just one of the many problems with it.) You should instead learn the php PDO extension. It is better written and is simpler and more straight-forward to use.