0

My login page just says

Parse Error: Unexpected end of file

enter image description here

Can you please help me?

I am Using XAMPP (I don't think that's the problem but I'm writing as many details as I can to make it easier to answer).

    <?php
$Password = $_POST['Password'];
$Password = hash('sha256', '$Password');

$host = "localhost";
$user = "root";
// $password = "";
$dbName = "db1";
$dbTable = "users";

$link = mysqli_connect ($host, $user, $password);
$query = "SELECT * from ".$dbTable." WHERE Username = '$Username' AND Password = '$Password'";
$result = mysql_db_query($dbName, $query, $link);

while ($row = mysql_fetch_array($result)) {
    print("$row[user]<br>");
    print("$row[domain]<br>");
}
mysql_close ($link);
if ($row[user] == $clientUser || $row[domain] == $clientDomain) {
    print("<h1>NOPE!</h1>\
");
?>



<!DOCTYPE html>
<html>
<head>
    <title>Log In</title>
</head>
<body>
    <form action="index.php" method="POST">
        <label>Username:</label>
        <br>
        <input type="text" name="Username" placeholder="Username">
        <br>
        <br>
        <label>Password:</label>
        <br>
        <input type="text" name="Password" placeholder="Password">
        <button type="submit" name="login">Log In</button>
    </form>
</body>
</html>
  • You're missing the `}` at the end of `if ($row[user] == $clientUser || $row[domain] == $clientDomain) {` – Barmar Jun 27 '18 at 21:12
  • 1
    Possible duplicate of [PHP parse/syntax errors; and how to solve them?](https://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) –  Jun 27 '18 at 21:22
  • You are open to SQL injections and having variable names only differing by case sensitivity is not a good idea. Additionally `'$Password'` is not the user's password, it is the literal `$Password`. – user3783243 Jun 27 '18 at 21:23
  • You shouldn't quote variables but if you have to know the difference https://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php. – user3783243 Jun 27 '18 at 21:24

2 Answers2

0

You probably not closed a brace for if condition in line number 22

see this answer

<?php
$Password = $_POST['Password'];
$Password = hash('sha256', '$Password');

$host = "localhost";
$user = "root";
// $password = "";
$dbName = "db1";
$dbTable = "users";

$link = mysqli_connect ($host, $user, $password);
$query = "SELECT * from ".$dbTable." WHERE Username = '$Username' AND Password = '$Password'";
$result = mysql_db_query($dbName, $query, $link);

while ($row = mysql_fetch_array($result)) {
    print("$row[user]<br>");
    print("$row[domain]<br>");
}
mysql_close ($link);
if ($row[user] == $clientUser || $row[domain] == $clientDomain) {
    print("<h1>NOPE!</h1>\
    ");
}
?>



<!DOCTYPE html>
<html>
<head>
    <title>Log In</title>
</head>
<body>
    <form action="index.php" method="POST">
        <label>Username:</label>
        <br>
        <input type="text" name="Username" placeholder="Username">
        <br>
        <br>
        <label>Password:</label>
        <br>
        <input type="text" name="Password" placeholder="Password">
        <button type="submit" name="login">Log In</button>
    </form>
</body>
</html>
Dhanu K
  • 11,288
  • 6
  • 24
  • 38
0
<?php
$Password = $_POST['Password'];
$Password = hash('sha256', '$Password');

$host = "localhost";
$user = "root";
// $password = "";
$dbName = "db1";
$dbTable = "users";

$link = mysqli_connect ($host, $user, $password);
$query = "SELECT * from ".$dbTable." WHERE Username = '$Username' AND Password = '$Password'";
$result = mysql_db_query($dbName, $query, $link);

while ($row = mysql_fetch_array($result)) {
    print("$row[user]<br>");
    print("$row[domain]<br>");
}
mysql_close ($link);
if ($row[user] == $clientUser || $row[domain] == $clientDomain) { 
print( "<h1>NOPE!</h1>");
}
?>



<!DOCTYPE html>
<html>
<head>
    <title>Log In</title>
</head>
<body>
    <form action="index.php" method="POST">
        <label>Username:</label>
        <br>
        <input type="text" name="Username" placeholder="Username">
        <br>
        <br>
        <label>Password:</label>
        <br>
        <input type="text" name="Password" placeholder="Password">
        <button type="submit" name="login">Log In</button>
    </form>
</body>
</html>
AraByte
  • 154
  • 9