This is my php code.And i get no database selected error while running it in the localhost.kindly help me please.

<?php
$hostname_localhost ="localhost";
$database_localhost ="mydatabase";
$username_localhost ="root";
$password_localhost ="";
$localhost = mysql_connect($hostname_localhost,$username_localhost,$password_localhost)
or
trigger_error(mysql_error());

mysql_select_db($database_localhost, $localhost);

$username = $_POST['username'];
$password = $_POST['password'];
$query_search = "select * from tbl_user where username = '".$username."' AND password = '".$password. "'";
$query_exec = mysql_query($query_search) or die(mysql_error());
$rows = mysql_num_rows($query_exec);
//echo $rows;
 if($rows == 0) { 
 echo "No Such User Found"; 
 }
 else  {
    echo "User Found"; 
}
?>

http://php.net/manual/en/function.mysqli-connect.php

$db_username        = 'PASSWORD'; //database username
$db_password        = ''; //dataabse password
$db_name            = 'DATABASE_NAME'; //database name
$db_host            = 'localhost'; //hostname or IP


$mysqli_conn = new mysqli($db_host, $db_username, $db_password,$db_name); //connect to MySql

//Output any connection error
if ($mysqli_conn->connect_error) {
    die('Error : ('. $mysqli_conn->connect_errno .') '. $mysqli_conn->connect_error);
}

I will post the code I posted on similar thread asked here on https://www.daniweb.com/web-development/php/threads/492929/problem-with-my-login-page-facing-with-a-blank-page

<?php
if(isset($_POST['username'])){
    $servername = "localhost";
    $dbname = "test";
    $dbusername = "root";
    $dbpassword = "";
    try {
        $conn = new PDO("mysql:host=$servername;dbname=$dbname", $dbusername, $dbpassword);
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $username = $_POST['username'];
        $password = $_POST['password'];
        $password = md5($password);
        $sql = "SELECT Password FROM Users WHERE Username = '$username'";
        $result = $conn->query($sql);

        if ($result->rowCount() > 0){
            foreach($result as $row) {
                if ($password == $row['Password']){
                    echo "Password correct!";
                    //header("Location: admin-area.php");
                }
            }
            echo "Password incorrect!";
        }else{
            echo "Username incorrect!";
        }
    } catch(PDOException $e) {
        echo $sql . "<br>" . $e->getMessage();
    }
    $conn = null;
}
?>
<html>
<head>
    <title>Login Page</title>
</head>
<body>
<form method="post">
Username: <input type="text" name="username"><br>
Password : <input type="text" name="password"><br>
<input type="submit" value="submit">
</form>
</body>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.