So little code, so many errors ...
Let's start with the three you haven't noticed, because they are the most important:
1) Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead.
When you concatenate strings, you cause problems because SQL receives commands like:
SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood'
The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:
SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable;
Which SQL sees as three separate commands:
SELECT * FROM MyTable WHERE StreetAddress = 'x';
A perfectly valid SELECT
DROP TABLE MyTable;
A perfectly valid "delete the table" command
And everything else is a comment.
So it does: selects any matching rows, deletes the table from the DB, and ignores anything else.
So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?
2) Never store passwords in clear text - it is a major security risk. There is some information on how to do it here:
Password Storage: How to do it.[
^]3)
And remember: if this is web based then GDPR applies and that means you need to handle passwords as sensitive data and store them in a safe and secure manner. Text is neither of those and the fines can be .... um ... outstanding. In December 2018 a German company received a relatively low fine of €20,000 for just that.
3) Never hard-code connection strings: if your code ever gets to production, it will fail immediately, because you connection string refers to a local instance of SQL server, and that won't be the case. Always store connection strings in a configuration file!
Now, the one you have noticed by can't fix yourself.
Look at the error message, it tells you two critical pieces of information: The error message "unexpected 'else'" and where it found it "on line 52".
So look at line 52 (most editors accept CTRL+G as a "go to line number" command):
else {
That matches what the error message says, so look upwards to find it's matching
if
:
if(count($row)!==0)
{
$databasepassword = $row[0]['password'];
if($databasepassword === $password) {
?>
<script>
alert('Login Successful');
</script>
<?php
}
else {
?>
<script>
alert('Login Failed');
</script>
<?php
}
else {
echo"All fields are required!";
}
There isn't one - probably because you forgot the closing curly bracket for teh if it should be "attached" to.
Move the closing curly bracket and correct the indentation to match.