• php登录注册


    php 登录注册

    注册代码:register.php

    <style type="text/css">
     form{
        300px;
        background-color:#EEE0E5;
        margin-left:300px;
        margin-top:30px;
        padding:30px;
     }
     button{
        margin-top:20px;
     }
    </style>
    <form method="post">
    <label>用户名:<input type="text" name="name"></label>
    <br/><br/>
    <label>密码:<input type="password" name="pw"></label>
    <br/><br/>
    <label>再次输入密码:<input type="password" name="repw"></label>
    <button type="submit" name="submit">注册</button>
    </form>
    <?php 
    $link = mysqli_connect('localhost', 'root', 'root', 'test');
    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }else {
        if (isset($_POST['submit'])){
            if ($_POST['pw'] == $_POST['repw']){
        $query = "insert into user (name,pw) values('{$_POST['name']}','{$_POST['pw']}')";
        $result=mysqli_query($link, $query);
        header("Location:login.php");
            }else {
                echo "<script>alert('两次输入密码不一致!')</script>";
            }
        }
    }
    ?>
    

    登录代码: login.php

    <style type="text/css">
     form{
        300px;
        background-color:#EEE0E5;
        margin-left:300px;
        margin-top:30px;
        padding:30px;
     }
    </style>
    <form method="post">
    <label>用户名:<input type="text" name="name"></label>
    <br/><br/>
    <label>密码:<input type="password" name="pw"></label>
    <br/><br/>
    <button type="submit" name="submit">登录</button>
    </form>
    <?php 
    $link = mysqli_connect('localhost', 'root', 'root', 'test');
    if (!$link){
        echo"<script>alert('数据库连接失败!')</script>";
    }else {
        if (isset($_POST['submit'])){
            $query = "select * from user where name = '{$_POST['name']}' and pw = '{$_POST['pw']}'";
            $result = mysqli_query($link, $query);
            if (mysqli_num_rows($result) == 1){
                header("Location:index.php");
            }
        }
    }
    ?>
    <?php 
    $link = mysqli_connect('localhost', 'root', 'root', 'test');
    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }else {
        if (isset($_POST['submit'])){
            if ($_POST['pw'] == $_POST['repw']){
        $query = "insert into user (name,pw) values('{$_POST['name']}','{$_POST['pw']}')";
        $result=mysqli_query($link, $query);
        header("Location:login.php");
            }else {
                echo "<script>alert('两次输入密码不一致!')</script>";
            }
        }
    }
    ?>
  • 相关阅读:
    超级迷宫我的计划表
    不敢死队
    Let the Balloon Rise
    Hangover
    汉诺塔系列2
    Tri Tiling(递推)
    Tiling(递推,高精度)
    Color Me Less
    I Think I Need a Houseboat(圆计算)
    Kbased Numbers(递推)
  • 原文地址:https://www.cnblogs.com/lvhanzhi/p/10722186.html
Copyright © 2020-2023  润新知