0

So I am trying to run this php file which should act as a login for users. Everytime I try to run it the browser says something like "localhost is currently unable to handle this request." I don't know what to do can anyone help me? Even running simple statements are coming back wit this error.

<?php

$host="localhost";
$user="root";
$password=" ";
$db="storm";

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

if(isset($_POST['username'])){

$uname=$_POST['username'];
$password=$_POST['password'];

$sql="select * from user where username='".$uname."'AND 
password='".$password."' limit 1";
$result=mysql_query($sql);

if(mysql_num_rows($result)==1){
    echo "you have logged in";
    exit();
}
else{
    echo"nice try";
}


?>
<!DOCTYPE html>
<html>
<head>
    <title> Login</title>

</head>
<body>
    <div class="container">
        <form>
        <div class="form-input">
        <input type="text" name="username" placeholder="Enter the User 
 Name"/>    
    </div>
    <div class="form-input">
        <input type="password" name="password" placeholder="password"/>
    </div>
    <input type="submit" type="submit" value="LOGIN" class="btn-login"/>
    </form>
</div>
</body>
</html>
  • 1
    You should never, ever create query strings by concatenating string values. You open yourself up to serious SQL Injection attacks. On a login it is even worse. You should always use prepared statements with parameter substitutions. – Dragonthoughts Apr 19 '19 at 04:44
  • 1
    On scurity grounds, you should never ever include passwords in plan form in a database. Unhashed passwords can be stolen and used very easily. – Dragonthoughts Apr 19 '19 at 04:45
  • 1
    If you are using PHP 7+ `mysql_` functions are no longer available. Even if you are using 5.4+ you should upgrade to PDO or mysqli and use prepared statements. – user3783243 Apr 19 '19 at 05:07
  • [related](https://stackoverflow.com/a/21797193/446594) – DarkBee Apr 19 '19 at 05:20

1 Answers1

0

The code you provided is missing one bracket at the end.

if(isset($_POST['username'])){ <--

...

if(mysql_num_rows($result)==1){
    echo "you have logged in";
    exit();
}
else{
    echo"nice try";
}
} <-- 
Raloriz
  • 30
  • 7