php没有连接

时间:2019-04-19 04:01:41

标签: php mysql

因此,我正在尝试运行此php文件,该文件应作为用户的登录名。每当我尝试运行它时,浏览器都会显示类似“本地主机当前无法处理此请求”之类的信息。我不知道该怎么办,有人可以帮助我吗?即使运行简单的语句也会因该错误而返回。

<?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 个答案:

答案 0 :(得分:0)

您提供的代码末尾缺少一个括号。

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

...

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