-1

I've just started learning how to implement databases into websites and thus have been trying to add a login function to my own website. However, when pressing submit to log in, I get the error: Parse error: syntax error, unexpected '$result' (T_VARIABLE) in /opt/lampp/htdocs/login/process.php on line 13.

Below is the code for my processing.php file:

<?php
    $username = $_POST['username'];
    $password = $_POST['password'];

    $username = stripcslashes($username);
    $password = stripcslashes($password);
    $username = mysql_real_escape_string($username);
    $password = mysql_real_escape_string($password);

    mysql_connect("localhost", "root", "");
    mysql_select_db("login")

    $result = mysql_query("select * from users where username = '$username' and password = '$password'")
            or die("Failed to query database ".mysql_error());
    $row = mysql_fetch_array($result);
    if($row['username'] == $username && $row['password'] == $password && ("" !== $username || "" !== $password)) {
        echo "Login Success! Welcome, ".$row['username'];
    } else {
        echo "Failed to Login!";
    }
?>

Any help is appreciated.

Dylan Haigh
  • 53
  • 1
  • 9
  • You forgot the `;` on the previous line. Voting to close as off-topic because the problem was caused by a typo. – Quentin Oct 21 '17 at 23:32
  • 2
    **Danger**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) that has been [removed](http://php.net/manual/en/mysql.php) from PHP. You should select a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). – Quentin Oct 21 '17 at 23:32
  • 3
    **Danger**: Blindly stripping slashes from data will destroy data. It is a defence against magic quotes which were removed from PHP years ago. – Quentin Oct 21 '17 at 23:33
  • 4
    **Danger**: "Not hashing at all" is [an unsuitable hashing algorithm](http://php.net/manual/en/faq.passwords.php); you need to [take better care](https://www.owasp.org/index.php/Password_Storage_Cheat_Sheet) of your users' passwords. – Quentin Oct 21 '17 at 23:33

1 Answers1

-1

You missed the semi column at the end to the following line

mysql_select_db("login")

applying semi column will fix the issue.

Moeen Basra
  • 733
  • 4
  • 18
  • 1
    Questions that are about basic PHP syntax errors should not be answered. They should be closed as a duplicate of [PHP Parse/Syntax Errors; and How to solve them?](//stackoverflow.com/questions/18050071) only. See: [Should one advise on off topic questions?](//meta.stackoverflow.com/q/276572/1768232). Off-topic questions can be closed and deleted, which could nullify your contribution anyway. – John Conde Oct 22 '17 at 18:53