Couldn't connect to my database

I’m pretty sure i have the correct php command and all the information correct but i end up getting the error which the page isn’t working and i couldnt find similar topic here.
here is my code:

<?php
$servername = "sql309.epizy.com";
$username   = "epiz_32096328";
$password   = "";
$dbname     = "epiz_32096328_mytutor_db";

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
?>

That error is there because your file didn’t send any data.
If you put this at the end of the file (before the closing ?>

else {
    echo "it's working!";
}

Does it still give that error

5 Likes

I have added this line but still get the same error when i access to the webpage

1 Like

I’m not sure, but it might be that the there is a security filter in the server that blocks access to the file dbconnect.php. After all, this is a file that’s typically used for database connection initialization, in which case there is no legitimate reason why anyone should access it directly.

Could you please try include-ing the file into another PHP script and open that one?

2 Likes

Thanks. I can now use my other php file but i have meet another new problem which is i couldn’t access to my database in order to retrieve my data for my application. I get this error when i try to access to my database on InfinityFree:
This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support

It sounds like this security system is preventing you from accessing your site:

Please understand that pages hosted with us are only accessible from regular web browsers (that support cookies and Javascript).

4 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.