Reputation: 41
I have created a basic page with php and MySQL, but somehow i seem to be getting this error. I Have tried entering my MySQL server password but it shows the same error anyway. I am hosting this page from 000webhost and i have just been introduced to coding.
<?php
$username= filter_input(INPUT_POST,'username');
$password= filter_input(INPUT_POST,'password');
if (!empty($username)) {
if (!empty($password)) {
$host = "localhost";
$dbusername = "root";
$dbpassword = "";
$dbname = "project";
//create connection
$conn = new mysqli($host, $dbusername, $dbpassword, $dbname);
//check connection
if(!$conn)
{
die("connection failed: ". mysqli_connect_errno());
}
else{
echo "Connected successfully";
}
}
else{
echo "password should not be empty";
die();
}
}
?>
Upvotes: 4
Views: 21348
Reputation: 1
If you use 000webhost, just change the database password in the database manager menu until the connection is successful. This is usually because the password contains prohibited characters.
Upvotes: 0
Reputation: 96
Make sure you are using correct value for $host, $dbusername, $dbname, $dbpassword from the database you want to connect. Please refer to the image below:
Upvotes: 0
Reputation: 13
Make your database in Database Manager first (in 000webhost). Then, change your $dbusername
, $dbpassword
, and $dbname
as provided by 000webhost.
Upvotes: 1
Reputation: 21
Follow these steps:
/bootstrap/cache
except .gitignore
.Upvotes: 1