4

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();
        }

        }
    ?>
Shruti
  • 41
  • 1
  • 1
  • 2
  • line number 12 refers to which line of code? – Rohit Sahu May 20 '20 at 08:12
  • Hi, you may find a solution in the accepted answer of this post : https://stackoverflow.com/questions/10299148/mysql-error-1045-28000-access-denied-for-user-billlocalhost-using-passw Have a great day – djleop May 20 '20 at 08:33
  • Don't login from your application using `root`. Root is the database's superuser, it should only be used for administration. Instead create a user account for this application which has only the permissions it actually needs in order to work – ADyson May 20 '20 at 08:37

4 Answers4

1

Make your database in Database Manager first (in 000webhost). Then, change your $dbusername, $dbpassword, and $dbname as provided by 000webhost.

Shany
  • 13
  • 5
0

Follow these steps:

  1. Make sure database password not contain * special character.
  2. Make sure your database name and database username are correct.
  3. Delete all files from /bootstrap/cache except .gitignore.
BSMP
  • 4,596
  • 8
  • 33
  • 44
Kathir
  • 11
  • 2
0

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:

enter image description here

0

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.

Aan B
  • 1