展示:

注册.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <title>注册</title>

</head>

<body>
    <div id="div1">
        <form enctype="\u4e00~\u9fa5" method="post" action="./login.php" name='form' id='form'>
            <table>
                <h2>注册</h2>
                <tr>
                    <td>
                        <p><span>账号:</span><input type="text" class="input" name='user' id='user'></p>
                    </td>
                </tr>

                <tr>
                    <td>
                        <p><span>密码:</span><input type="password" id='pasd' class="input" name='pasd'></p>
                    </td>
                </tr>
                <tr>
                    <td>
                        <input class="buttorn" type="submit" name='submit' id='submit' value="注册"
                            onclick="returncheck(form);">
                        <input class="buttorn" type="reset" name='reset' id='reset' value="重填">
                    </td>
                </tr>
            </table>
        </form>
    </div>


</body>

</html>

登陆.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <title>登陆</title>

</head>

<body>
    <div id="div1">
        <form enctype="\u4e00~\u9fa5" method="post" name='denglu' action='./login2.php'>
            <table>

                <h2>登录</h2>
                <tr>
                    <td>
                        <p><span>账号:</span><input type="text" name='username' class="input"></p>
                    </td>
                </tr>
                <tr>
                    <td>
                        <p><span>密码:</span><input type="password" name='password' pattern="\u4e00~\u9fa5" class="input"
                                maxlength="9" autofocus></p>
                    </td>
                </tr>
                <tr>
                    <td><input class="buttorn" type="submit" value="登录" readonly="readonly"><a href="./注册.html"><input
                                class="buttorn" onclick="window.location.href('./注册.html')" type="button" value="注册"
                                readonly="readonly"></a></td>
                </tr>
            </table>
        </form>
    </div>
</body>

</html>

welcom.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <title>welcome</title>
    <style>


    </style>
</head>

<body>
    <div id="div1">
        <h2>欢迎您!</h2>
    </div>
</body>

</html>

style.css

#div1 {
    background-image: url(./form_bg.jpg);
    background-position: left top;
    width: 1431px;
    height: 717px;
    background-repeat: no-repeat;
    position: relative;
}

body,
form,
h1,
p,
div {
    margin: 0px;
    padding: 0px;
}

body {
    font-family: 微软雅黑;
    font-size: 12px;
}

form {
    width: 600px;
    height: 400px;
    margin-top: 50px;
    margin-bottom: 50px;
    margin-left: auto;
    margin-right: auto;
    padding-left: 30px;
    position: absolute;
    left: 48%;
    top: 10%;
}

h2 {
    text-align: center;
    ;
    margin-top: 16px;
    margin-bottom: 16px;
    margin-left: -20px;
    margin-right: 150px;
    font-size: 40px;
}

p {
    margin-top: 20px;
}

span {
    width: 75px;
    display: inline-block;
    padding-right: 10px;
    text-align: right;
}

.input {
    width: 200px;
    height: 18px;
    border: 1px solid #38a1bf;
    padding: 2px;
}

#input {
    width: 100px;
    height: 24px;
}

.buttorn {
    width: 100px;
    height: 30px;
    background-color: #93b518;
    margin-top: 20px;
    margin-left: 75px;
    border-radius: 3px;
    font-size: 18px;
    font-family: 微软雅黑;
    color: white;
}

span {
    font-size: 20px;
}

login.php(注册用的)

<?php
header("Content-type:text/html;charest=utf-8");
session_start();
 if (!isset($_POST['user'])){
    echo "<script type='text/javascript'>alert('您的表单还没填完!');</script>";
    exit("错误执行");
}

include('./connect.php');

$user=$_POST['user'];
$pasd=$_POST['pasd'];

$result2=mysqli_query($conn,'select * from denglu where username=$user');
if($result2){
    echo "<script type='text/javascript'>alert('已存在该用户!');</script>";
}
else{
$result3=mysqli_query($conn,"insert into denglu(id,username,password) values(null,'$user','$pasd');");
echo "<script type='text/javascript'>alert('注册成功!');</script>";
}
mysqli_close($conn);//关闭数据库
?>

login2.php(登陆用的)

<?PHP
    header("Content-Type: text/html; charset=utf8");
    if(!isset($_POST["submit"])){
        exit("错误执行");
    }//检测是否有submit操作 

    include('./connect.php');//链接数据库
    $username = $_POST['username'];//post获得用户名表单值
    $passowrd = $_POST['password'];//post获得用户密码单值

    if ($name && $passowrd){//如果用户名和密码都不为空
             $sql = "select * from denglu where username = '$username' and password='$passowrd'";//检测数据库是否有对应的username和password的sql
             $result = mysqli_query($conn,$sql);//执行sql
             $rows=mysqli_num_rows($result);//返回一个数值
             if($rows){//0 false 1 true
                   header("refresh:0;url=welcome.html");//如果成功跳转至welcome.html页面
                   exit;
             }else{
                echo "用户名或密码错误";
                echo "
                    <script>
                            setTimeout(function(){window.location.href='login.html';},1000);
                    </script>

                ";//如果错误使用js 1秒后跳转到登录页面重试,让其从新进行输入
             }
             

    }else{//如果用户名或密码有空
                echo "表单填写不完整";
                echo "
                      <script>
                            setTimeout(function(){window.location.href='login.html';},1000);
                      </script>";
                        //如果错误使用js 1秒后跳转到登录页面重试,让其从新进行输入
    }

    mysqli_close($conn);//关闭数据库
?>

connect.php(连接数据库)

<?php
$dbhost = "127.0.0.1";
$dbuser = 'root';
$dbname = "denglu";	//数据库名称
$dbtable='denglu';
$dbpass = "";	//数据库密码
$conn=mysqli_connect($dbhost,$dbuser,$dbpass);
if($conn=mysqli_connect($dbhost,$dbuser,$dbpass)){
    echo "<script type='text/javascript'>alert('连接成功');</script>";
}
else{
    echo "<script type='text/javascript'>alert('连接失败');</script>";
}
$connt=mysqli_select_db($conn,$dbname);
?>

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐