只需尝试连接数据库(初学者)时SQL语法出错

I already used some solutions put forward in other threads but it just doesn't want to work. My MYSQL version is: 5.5.38 and here is the code I use (the goal is to simply connect to the database). The code goes on, that's why the "{" is not closed from the if-clause, but the important part that should connect to the database is listed below:

$user = mysql_real_escape_string($_POST['user']);
$password = ($_POST['password']);

if ($_POST['user'] <> "" AND $_POST['password'] <> "")
{
mysql_connect('localhost', 'xxx', 'xxx');
mysql_select_db('xxx');

$sql = "SELECT * AS user FROM xxx WHERE nutzer LIKE '$nutzer' AND pw LIKE '$password'" ;

$result = mysql_query($sql);
if (false === $result) {
die (mysql_error());
}

$datensatz = mysql_fetch_array($result, MYSQL_ASSOC);

These errors come right at the beginning when I just open the site:

Warning: mysql_real_escape_string(): Access denied for user ''@'localhost' (using password: NO) in /var/www/web1159/html/lehrer.php on line 15

Warning: mysql_real_escape_string(): A link to the server could not be established in /var/www/web1159/html/lehrer.php on line 15

And this is the error on which I stumble when I try to log in and connect to the database. I know what it says, but it does not make much sense to me - are the " or ' wrongly placed? I tried other variations - still doesn't work. And why line 1??:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS user FROM lehrerzugang WHERE nutzer LIKE '' AND pw LIKE 'lfb'' at line 1

Setup your database connection before calling mysql_real_escape_string.

Besides the default username and passowrd for localhost are 'root' and empty string '', so unless you have explicitly changed these credentials you need to provide the access as root user with empty sting password.

mysql_connect('localhost', 'root', '');
mysql_select_db('yourDatabase');

If you have setup your own user access to the database then make sure you provide the correct credentials.

mysql functions are now deprecated in PHP and there is an Improved MYSQL library to support database connection and muanipulation mysqli, so use it.

You cannot give an alias to all columns selection * so SELECT * AS is invalid, aliases can be given to specific column selection SELECT dateOfBirth AS DOB, dateCreated AS DC FROM yourTable