如何使用php和mysql创建登录系统

时间:2018-04-20 06:09:28

标签: php mysql login

我是mysql初学者,我尝试使用php和mysql创建一个登录系统。但是,下面是我的脚本无法正常工作,请帮助我如何使用php和mysql创建登录系统。

数据库照片 mysql photo

我的PHP代码

        <form action="#" method="post" >
            <div class="user_login">
            <center>
                <input type="text" id="id" placeholder="User ID" name="name">
            </center>
            <br>
            <center>
                <input type="text" id="password" placeholder="Password" name="pass">
            </center>
            <br>
            <center>
                <input type= "submit" value ="login" name="submit">
            </center>
            </div>
    </form>

 <?php
    $servername = "localhost";
    $username = "root";
    $password = "";
    $db = "wms";
    $con = new mysqli($servername, $username, $password, $db);


if(isset($_POST['submit'])){
    $select = "select from user WHERE user_name='".$_POST['name']."' AND password='".$_POST['pass']."'";
    $query= mysqli_query($con,$select); 
    if($con || mysqli_num_rows($query) == 1){echo "<br><center> login successfully</center>";}
    else{echo "<br><center>login fail</center>";}
}
?> 

1 个答案:

答案 0 :(得分:0)

在互联网上有关于登录系统的数量超过数千个帖子。 顺便说一句,mysqli选择查询有错误更正。

$select = "select * from user WHERE user_name='".$_POST['name']."' AND password='".$_POST['pass']."'";

详细介绍了使用php和mysql登录系统,你可以按照这个url。 https://www.phpkida.com/php-tutorial/php-login-script/