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