-5

Parse error: syntax error, unexpected '$user' (T_VARIABLE) in C:\xampp\htdocs\home\login.php on line 4

    <?php

$host = "localhost"
$user = "root";    <------ line 4
$pass = "";
$db = "table";

mysql_connect($host, $user, $pass);
mysql_select_db($db);

if (isset($_POST['username'])) {
    $username = $_POST['username'];
    $password = $_POST['password']; 

    $sql = "SELECT * FROM users WHERE username='$username' AND password='$password'";
    $res = mysql_query($sql);

    if (mysql_num_rows($res) == 1) {
        echo "Super";
        exit();
    } else {
        echo "Siper";
        exit();
    }
}

?>

How can resolved this?

Peter Hook
  • 13
  • 2

2 Answers2

1

Missing semicolon:

 <?php

$host = "localhost"; <--- error :D
$user = "root";    <------ line 4
$pass = "";
$db = "table";

mysql_connect($host, $user, $pass);
mysql_select_db($db);

if (isset($_POST['username'])) {
    $username = $_POST['username'];
    $password = $_POST['password']; 

    $sql = "SELECT * FROM users WHERE username='$username' AND password='$password'";
    $res = mysql_query($sql);

    if (mysql_num_rows($res) == 1) {
        echo "Super";
        exit();
    } else {
        echo "Siper";
        exit();
    }
}

?>
Faisal Ashfaq
  • 2,545
  • 4
  • 28
  • 41
1

You're missing a semicolon on the first line. Remember that in php, errors often refer to something around the line number stated, and not necessarily on the line. :)

i.e.

 $host = "localhost";

Edit:

You may also want to sanitize your $_POST data, or re-think the way you're structuring this, as otherwise you're leaving things open to SQL injection.

Take a read through here for more information: What's the best method for sanitizing user input with PHP?

Community
  • 1
  • 1
XtraSimplicity
  • 5,704
  • 1
  • 28
  • 28