没有选择数据库[关闭]

include 'connect.php';

        $sql = "SELECT 
                    user_id,
                    user_name,
                    user_level
                FROM
                    users
                WHERE
                    user_name = '" . mysql_real_escape_string($_POST['user_name']) . "'
                AND
                    user_pass = '" . sha1($_POST['user_pass']) . "'";

        $result = mysql_query($sql);
        if(!$result)
        {

            echo 'Something went wrong while signing in. Please try again later.';
            //echo mysql_error(); //debugging purposes, uncomment when needed
        }

Can someone please have a look at this and fix the error. This is the error: No Database selected. I took signin.php from an online tutorial which might be outdated. It would help if someone told me if it would be ok to keep $server as localhost. Please remember that I'm new to programming and may make basic mistakes. This is connect.php: It works, I've tested it with signup.php

<?php
//connect.php
$server = 'localhost';
$username   = 'xxx';
$password   = 'xxx';
$database   = 'xxx';
$mysqli = new mysqli("$server", "$username", "$password", "$database");
if(!mysqli_connect($server, $username,  $password))
{
exit('Error: could not establish database connection');
}
?>

You must set the $database in the mysqli_connect

if(!mysqli_connect($server, $username,  $password, $database))

And there is no need for this line since you don't use this variable in your code:

$mysqli = new mysqli("$server", "$username", "$password", "$database");

In connect.php you connect with the Mysqli extension, so you should use this in your script:

$result= mysqli_query($mysqli, $sql);