Hi, i just hosted my website on 000webhost for free and somehow i cant connect with my database resulting to that i cant login on my website. How can i solve that? Please help. thank you

Heres my code for db connection

'<?php

$db_host="mysql1.000webhost.com";
$db_username="a1924971_user";
$db_password="*************";
$db = "a1924971_learn";

$cn = mysqli_connect($db_host,$db_username,$db_password,$db);


if(!$cn){
    die(mysqli_connect_error());
}

?> '

Does the error message provide useful information? If you have another way of accessing the database, control panel or ssh, etc, you can test out connecting via those means.
But the basics you have there look right from a code perspective so the problem might lie in the username/password or configuration that your host hasn't set up right.

I highly doubt that your free host has database in the same server. In other words, $db_host="mysql1.000webhost.com"; is very likely to be wrong. You need to find out what you really need to connect to from your host. Normally, they would have it as an IP address, not a DNS...

Can you go to your 000webhost cpanel and look for servername on the right panel..

Dont use mysql as it was deprecated, use mysqli or PDO try this..

 <?php 
    try{
    $db_host="mysql1.000webhost.com";// change to localhost or servername
    $db_username="a1924971_user";
    $db_password="*************";
    $db = "a1924971_learn";
    $cn = new PDO("mysql:host=$db_host;dbname=$db",$db_username,$db_password);
    $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    }catch(PDOException $e){
        echo $e->getMessage();
    }
 ?>