php用户管理系统(简单)学习教程

最近因为工作原因需要使用php开发网页,所以开始学习php,在学习的过程中也遇到了很多困难,经过不断的查询百度各种学习资料,逐步的客服了这些困难和疑惑,现在我将学习过程中编写的代码分享给有需要的朋友,仅供参考。

此系统比较简单,基本含有了用户管理系统的注册、登录、修改资料、找回密码等功能,共14个php页面,分别为conn.php(数据库连接),index.php(首页),chkuser.php(登录判断),welcome.php(登录成功), loginfail.php(登录失败),logout.php(注销用户),register.php(注册用户),regok.php(注册成功), regfail.php(注册失败),userupdate.php(修改用户资料),userupdateok.php(修改用户资料后台),lostpassword.php(找回密码),showquestion.php(提示问题),showpassword.php(显示密码);css样式表一个;sql数据库导出文件一个;项目文件夹名称为UserSystem,下级目录为css、sql以及14个php页面文件;此项目源码我已经上传至《资源下载》,连接地址为(https://download.csdn.net/download/modern358/11064366)请自行查找下载。

下面我对代码分别说明:

1.数据库

-- phpMyAdmin SQL Dump
-- version 4.8.4
-- https://www.phpmyadmin.net/
--
-- 主机: 127.0.0.1
-- 生成日期: 2019-03-26  
-- 服务器版本: 10.1.37-MariaDB
-- PHP 版本: 7.3.1

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- 数据库: `member`
--
CREATE DATABASE IF NOT EXISTS `member` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
USE `member`;

-- --------------------------------------------------------

--
-- 表的结构 `member`
--
-- 创建时间: 2019-03-25  
--

CREATE TABLE `member` (
  `id` int(11) NOT NULL,
  `username` varchar(20) NOT NULL,
  `password` varchar(20) NOT NULL,
  `question` varchar(50) NOT NULL,
  `answer` varchar(50) NOT NULL,
  `truename` varchar(50) DEFAULT NULL,
  `sex` varchar(10) DEFAULT NULL,
  `address` varchar(50) DEFAULT NULL,
  `tel` varchar(50) DEFAULT NULL,
  `qq` varchar(20) DEFAULT NULL,
  `email` varchar(50) DEFAULT NULL,
  `authority` char(1) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- 表的关系 `member`:
--

--
-- 转存表中的数据 `member`
--

INSERT INTO `member` (`id`, `username`, `password`, `question`, `answer`, `truename`, `sex`, `address`, `tel`, `qq`, `email`, `authority`) VALUES
(8, 'admin', '123', '2', '清华大学湖心分校', '管理员', '男', '白银市', '13899000099', '55555', 'admin@11.com', '0'),
(9, 'zhang1', '234', '1', '平川一中', '张得熊', '男', '平川区', '13800000000', '12345', 'zhang@qq.com', '0');

--
-- 转储表的索引
--

--
-- 表的索引 `member`
--
ALTER TABLE `member`
  ADD PRIMARY KEY (`id`);

--
-- 在导出的表使用AUTO_INCREMENT
--

--
-- 使用表AUTO_INCREMENT `member`
--
ALTER TABLE `member`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=10;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

此数据库导出文件中,有用的部分就是CREATE DATABASE member和建立数据表CREATE TABLE member,以及INSERT INTO member。

2.index.php(首页)

<html>
<head>
    <title>会员管理系统</title>
    <link rel="stylesheet" href="css/style.css">

    <?php
    /**
     * Created by PhpStorm.
     * User: jiawei
     * Date: 2019/3/25
     */

    ?>
</head>
<body>
<form name="form1" method="post" action="chkuser.php">
    <div class="login">
        <table class="login_tb">
            <tr>
                <td>用户名:<input type="text" name="username" id="username"></td>
            </tr>
            <tr>
                <td>密&nbsp;&nbsp;码:<input type="text" name="pwd" id="pwd"></td>
            </tr>
            <tr>
                <td><input type="submit" name="button1" id="button1" value="登 录">
                <input type="reset" name="button2" id="button2" value="重 置"></td>
            </tr>
            <tr>
                <td><a href="register.php">注册新用户</a>&nbsp;&nbsp;<a href="lostpassword.php">找回密码</a> </td>
            </tr>
        </table>
    </div>
</form>

</body>
</html>

3.chkuser.php(登录判断)

<?php
/**
 * Created by PhpStorm.
 * User: jiawei
 * Date: 2019/3/25
 */

$user_name = $_POST['username'];
$password = $_POST['pwd'];

class chkinput
{
    var $m_username;
    var $m_password;
    function __construct($name,$pwd)
    {
        $this->m_username = $name;
        $this->m_password = $pwd;
    }

    function checkinput()
    {
        include ('conn.php');
        $sql = mysqli_query($conn,"SELECT * FROM member WHERE username='$this->m_username'");
        $info = mysqli_fetch_array($sql);
        if($info == false)
        {
            echo "<script>alert('用户不存在!');history.back();</script>";
            exit;
        }
        else
        {
            if($info['authority'] == 1)
            {
                echo "<script>alert('该用户已被冻结!');history.back();</script>";
                exit;
            }
            if($info['password'] == $this->m_password)
            {
                session_start();
                $_SESSION['username'] = $info['username'];
                $_SESSION['id'] = $info['id'];
                header("location:welcome.php");
                exit;
            }
            else
            {
                echo "<script>alert('密码输入错误!');history.back();</script>";
                header("location:loginfail.php");
                exit;
            }
        }

    }
}

$obj = new chkinput($user_name,$password);
$obj->checkinput();

4.welcome.php(登录成功)

<html>
<head>
    <title>登录成功</title>
    <link rel="stylesheet" href="css/style.css">


</head>
<body>

<div class="login">
    <p><strong>登录成功</strong></p>
    <span id="welcome_name">用户:XXXXXXX欢迎您!</span>
    <p><a href="userupdate.php">修改你的资料</a></p>
    <p><a href="logout.php">注销你的用户</a></p>
    <?php
    /**
     * Created by PhpStorm.
     * User: jiawei
     * Date: 2019/3/25
     */
    session_start();
    $ID =@ $_SESSION['id'];
    $user_name =@ $_SESSION['username'];
    if($user_name != "")
    {
        echo "<script>document.getElementById('welcome_name').innerText = '用户:$user_name 欢迎您!';</script>";
    }
    ?>
</div>

</body>
</html>

5. loginfail.php(登录失败)

<html>
<head>
    <title>登录失败</title>
    <link rel="stylesheet" href="css/style.css">

    <?php
    /**
     * Created by PhpStorm.
     * User: jiawei
     * Date: 2019/3/25
     */

    ?>
</head>
<body>

    <div class="login">
        <p><strong>登录失败</strong></p>
        <span>登录失败,请检查你填写的用户名和密码是否正确!</span>
        <p>请单击<a href="index.php">这里</a>重新登录。</p>
    </div>

</body>
</html>





6.logout.php(注销用户)

<html>
<head>
    <title>注销用户</title>
    <link rel="stylesheet" href="css/style.css">
</head>
<body>

<div class="login">
    <p><strong>注销用户</strong></p>
    <span>谢谢您的访问,您已安全退出!</span>
    <p>重新登录请单击<a href="index.php">这里</a>。</p>
    <?php
    /**
     * Created by PhpStorm.
     * User: jiawei
     * Date: 2019/3/25
     */
        session_start();
        session_destroy();
    ?>
</div>

</body>
</html>

7.register.php(注册用户)

<html>
<head>
    <title>用户注册</title>
    <link rel="stylesheet" href="css/style.css">
    <script type="text/javascript">
        function chkinput(form)
        {
            if(form.user_name.value == "")
            {
                form.user_name.style.backgroundColor = "red";
                document.getElementById("error_note").innerText = "提示:请输入昵称。";
                form.user_name.select();
                return false;
            }
            if(form.password.value == "")
            {
                form.password.style.backgroundColor = "red";
                document.getElementById("error_note").innerText = "提示:请输入密码。";
                form.password.select();
                return false;
            }
            if(form.password1.value == "")
            {
                form.password1.style.backgroundColor = "red";
                document.getElementById("error_note").innerText = "提示:请输入确认密码。";
                form.password1.select();
                return false;
            }
            if(form.password.value.length < 3)
            {
                form.password.style.backgroundColor = "red";
                document.getElementById("error_note").innerText = "提示:密码长度应该大于3位。";
                form.password.select();
                return false;
            }
            if(form.password.value != form.password1.value)
            {
                form.password1.style.backgroundColor = "red";
                document.getElementById("error_note").innerText = "提示:密码与重复密码不一致。";
                form.password.select();
                return false;
            }
            if(form.true_name.value == "")
            {
                form.true_name.style.backgroundColor = "red";
                document.getElementById("error_note").innerText = "提示:请输入真实姓名。";
                form.true_name.select();
                return false;
            }
            if(form.email.value == "")
            {
                form.email.style.backgroundColor = "red";
                document.getElementById("error_note").innerText = "提示:请填写EMAIL。";
                form.email.select();
                return false;
            }
            if(form.email.value.indexOf('@') < 0)
            {
                form.email.style.backgroundColor = "red";
                document.getElementById("error_note").innerText = "提示:请输入正确的EMAIL。";
                form.email.select();
                return false;
            }
            if(form.tel.value == "")
            {
                form.tel.style.backgroundColor = "red";
                document.getElementById("error_note").innerText = "提示:请输入联系电话。";
                form.tel.select();
                return false;
            }
            if(form.answer.value == "")
            {
                form.answer.style.backgroundColor = "red";
                document.getElementById("error_note").innerText = "提示:请输入密码提示答案。";
                form.answer.select();
                return false;
            }
            document.getElementById("error_note").innerText = "&nbsp;";
            return true;
        }
    </script>
</head>
<body>

    <?php
    /**
     * Created by PhpStorm.
     * User: jiawei
     * Date: 2019/3/25
     */

    ?>
    <form name="form1" method="post" action="regok.php" onsubmit="return chkinput(this)">
        <div class="register">
            <table class="register_tb">
                <caption>请填写用户信息</caption>
                <tr>
                    <td class="tb_alignr">用户名:</td>
                    <td class="tb_alignl"><input type="text" name="user_name" id="user_name">*</td>
                </tr>
                <tr>
                    <td class="tb_alignr">密&nbsp;&nbsp;码:</td>
                    <td class="tb_alignl"><input type="text" name="password" id="password">*</td>
                </tr>
                <tr>
                    <td class="tb_alignr">确认密码:</td>
                    <td class="tb_alignl"><input type="text" name="password1" id="password1">*</td>
                </tr>
                <tr>
                    <td class="tb_alignr">真实姓名:</td>
                    <td class="tb_alignl"><input type="text" name="true_name" id="true_name"></td>
                </tr>
                <tr>
                    <td class="tb_alignr">性别:</td>
                    <td class="tb_alignl"><input type="radio" name="sex" id="sex_m" value="男">
                        <label for="sex_m">男</label>&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="radio" name="sex" id="sex_w" value="女" checked="checked">
                        <label for="sex_w">女</label>
                    </td>
                </tr>
                <tr>
                    <td class="tb_alignr">E-mail:</td>
                    <td class="tb_alignl"><input type="text" name="email" id="email"></td>
                </tr>
                <tr>
                    <td class="tb_alignr">电话:</td>
                    <td class="tb_alignl"><input type="text" name="tel" id="tel"></td>
                </tr>
                <tr>
                    <td class="tb_alignr">QQ:</td>
                    <td class="tb_alignl"><input type="text" name="qq" id="qq"></td>
                </tr>
                <tr>
                    <td class="tb_alignr">地址:</td>
                    <td class="tb_alignl"><input type="text" name="address" id="address"></td>
                </tr>
                <tr>
                    <td class="tb_alignr">密码提示问题:</td>
                    <td class="tb_alignl">
                        <select name="question" id="question">
                            <option value="0">你的小学名字叫什么?</option>
                            <option value="1">你的中学名字叫什么?</option>
                            <option value="2">你的大学名字叫什么?</option>
                            <option value="3">你的母亲名字叫什么?</option>
                            <option value="4">你的父亲名字叫什么?</option>
                            <option value="5">你的配偶名字叫什么?</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="tb_alignr">密码提示答案:</td>
                    <td class="tb_alignl"><input type="text" name="answer" id="answer"></td>
                </tr>
                <tr>
                    <td class="tb_alignr"><input type="hidden" name="authority" id="authority" value="0"></td>
                    <td class="tb_alignl"><input type="submit" name="button1" id="button1" value="注 册">
                        <input type="reset" name="button2" id="button2" value="重 写">
                    </td>
                </tr>
            </table>
            <p id="error_note" style="text-align: left;font-size:12px;color:red;">&nbsp;</p>
        </div>
    </form>
</body>
</html>

8.regok.php(注册成功)

<html>
<head>
    <title>注册成功</title>
    <link rel="stylesheet" href="css/style.css">
</head>
<body>

<div class="login">
    <p><strong>注册成功</strong></p>
    <p>恭喜您!您已注册成功。</p>
    <p>请单击<a href="index.php">这里</a>登录</p>
    <?php
    /**
     * Created by PhpStorm.
     * User: jiawei
     * Date: 2019/3/25
     */

    include ('conn.php');
    $user_name = $_POST['user_name'];
    $sql = mysqli_query($conn,"SELECT * FROM member WHERE username='$user_name'");
    $info = mysqli_fetch_array($sql);
    if($info ===  true)
    {
        echo "对不起,该昵称已经被占用了。";
        header("location:regfail.php");

    }
    else
    {

        $user_name = $_POST['user_name'];
        $password = $_POST['password1'];
        $true_name = $_POST['true_name'];
        $sex = $_POST['sex'];
        $email = $_POST['email'];
        $tel = $_POST['tel'];
        $qq = $_POST['qq'];
        $address = $_POST['address'];
        $question = $_POST['question'];
        $answer = $_POST['answer'];
        $authority = $_POST['authority'];
        mysqli_query($conn,"INSERT INTO member (username,password,question,answer,truename,sex,address,tel,qq,email,authority)
          VALUES('$user_name','$password','$question','$answer','$true_name','$sex','$address','$tel','$qq','$email','$authority')");

    }
    ?>
</div>

</body>
</html>


9. regfail.php(注册失败)

<?php
/**
 * Created by PhpStorm.
 * User: jiawei
 * Date: 2019/3/25
 */
//忘记写这个了,各位自己实现一下吧!
?>

10.userupdate.php(修改用户资料)

<html>
<head>
    <title>修改用户资料</title>
    <link rel="stylesheet" href="css/style.css">
    <script type="text/javascript">
        function chkinput(form)
        {
            if(form.user_name.value == "")
            {
                form.user_name.style.backgroundColor = "red";
                document.getElementById("error_note").innerText = "提示:请输入昵称。";
                form.user_name.select();
                return false;
            }
            if(form.password.value == "")
            {
                form.password.style.backgroundColor = "red";
                document.getElementById("error_note").innerText = "提示:请输入密码。";
                form.password.select();
                return false;
            }
            if(form.password1.value == "")
            {
                form.password1.style.backgroundColor = "red";
                document.getElementById("error_note").innerText = "提示:请输入确认密码。";
                form.password1.select();
                return false;
            }
            if(form.password.value.length < 3)
            {
                form.password.style.backgroundColor = "red";
                document.getElementById("error_note").innerText = "提示:密码长度应该大于3位。";
                form.password.select();
                return false;
            }
            if(form.password.value != form.password1.value)
            {
                form.password1.style.backgroundColor = "red";
                document.getElementById("error_note").innerText = "提示:密码与重复密码不一致。";
                form.password.select();
                return false;
            }
            if(form.true_name.value == "")
            {
                form.true_name.style.backgroundColor = "red";
                document.getElementById("error_note").innerText = "提示:请输入真实姓名。";
                form.true_name.select();
                return false;
            }
            if(form.email.value == "")
            {
                form.email.style.backgroundColor = "red";
                document.getElementById("error_note").innerText = "提示:请填写EMAIL。";
                form.email.select();
                return false;
            }
            if(form.email.value.indexOf('@') < 0)
            {
                form.email.style.backgroundColor = "red";
                document.getElementById("error_note").innerText = "提示:请输入正确的EMAIL。";
                form.email.select();
                return false;
            }
            if(form.tel.value == "")
            {
                form.tel.style.backgroundColor = "red";
                document.getElementById("error_note").innerText = "提示:请输入联系电话。";
                form.tel.select();
                return false;
            }
            if(form.answer.value == "")
            {
                form.answer.style.backgroundColor = "red";
                document.getElementById("error_note").innerText = "提示:请输入密码提示答案。";
                form.answer.select();
                return false;
            }
            document.getElementById("error_note").innerText = "&nbsp;";
            return true;
        }
    </script>
</head>
<body>

    <?php
    /**
     * Created by PhpStorm.
     * User: jiawei
     * Date: 2019/3/25
     */
    session_start();
    $ID = $_SESSION['id'];
    require_once ('conn.php');
    $sql = mysqli_query($conn,"SELECT * FROM member WHERE id='$ID'");
    $info = mysqli_fetch_array($sql);

    ?>
<form name="form1" method="post" action="userupdateok.php" onsubmit="return chkinput(this)">
    <div class="register">
        <table class="register_tb">
            <caption>修改用户信息</caption>
            <tr>
                <td class="tb_alignr">用户名:</td>
                <td class="tb_alignl"><input type="text" name="user_name" id="user_name"  readonly="readonly"
                                         value="<?php echo $info['username'];?>">*</td>
            </tr>
            <tr>
                <td class="tb_alignr">密&nbsp;&nbsp;码:</td>
                <td class="tb_alignl"><input type="text" name="password" id="password" value="<?php echo $info['password']?>">*</td>
            </tr>
            <tr>
                <td class="tb_alignr">确认密码:</td>
                <td class="tb_alignl"><input type="text" name="password1" id="password1" value="<?php echo $info['password']?>" >*</td>
            </tr>
            <tr>
                <td class="tb_alignr">真实姓名:</td>
                <td class="tb_alignl"><input type="text" name="true_name" id="true_name" value="<?php echo $info['truename']?>"></td>
            </tr>
            <tr>
                <td class="tb_alignr">性别:</td>
                <td class="tb_alignl"><input type="radio" name="sex" id="sex_m" value="男" <?php if($info['sex'] === "男"){echo "checked = 'checked'";} ?> >
                    <label for="sex_m">男</label>&nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="radio" name="sex" id="sex_w" value="女" <?php if($info['sex'] === "女"){echo "checked = 'checked'";} ?> >
                    <label for="sex_w">女</label>
                </td>
            </tr>
            <tr>
                <td class="tb_alignr">E-mail:</td>
                <td class="tb_alignl"><input type="text" name="email" id="email" value="<?php echo $info['email']?>"></td>
            </tr>
            <tr>
                <td class="tb_alignr">电话:</td>
                <td class="tb_alignl"><input type="text" name="tel" id="tel" value="<?php echo $info['tel']?>"></td>
            </tr>
            <tr>
                <td class="tb_alignr">QQ:</td>
                <td class="tb_alignl"><input type="text" name="qq" id="qq" value="<?php echo $info['qq']?>"></td>
            </tr>
            <tr>
                <td class="tb_alignr">地址:</td>
                <td class="tb_alignl"><input type="text" name="address" id="address" value="<?php echo $info['address']?>"></td>
            </tr>
            <tr>
                <td class="tb_alignr">密码提示问题:</td>
                <td class="tb_alignl">
                    <select name="question" id="question">
                        <option value="0">你的小学名字叫什么?</option>
                        <option value="1">你的中学名字叫什么?</option>
                        <option value="2">你的大学名字叫什么?</option>
                        <option value="3">你的母亲名字叫什么?</option>
                        <option value="4">你的父亲名字叫什么?</option>
                        <option value="5">你的配偶名字叫什么?</option>
                        <?php
                        $question = $info['question'];
                        echo "<script>document.getElementById('question').selectedIndex = $question;</script>"
                        ?>
                    </select>
                </td>
            </tr>
            <tr>
                <td class="tb_alignr">密码提示答案:</td>
                <td class="tb_alignl"><input type="text" name="answer" id="answer" value="<?php echo $info['answer']?>"></td>
            </tr>
            <tr>
                <td class="tb_alignr"><input type="hidden" name="authority" id="authority" value="<?php echo $info['authority']?>">
                <input type="hidden" name="id1" id="id1" value="<?php echo $info['id']?>"></td>
                <td class="tb_alignl"><input type="submit" name="button1" id="button1" value="确 认">
                    <input type="reset" name="button2" id="button2" value="重 写">
                </td>
            </tr>
        </table>
        <p id="error_note" style="text-align: left;font-size:12px;color:red;">&nbsp;</p>
    </div>
</form>
</body>
</html>

11.userupdateok.php(修改用户资料后台)

<html>
<head>
    <title>修改成功</title>
    <link rel="stylesheet" href="css/style.css">
</head>
<body>

<div class="login">
    <p><strong>修改成功</strong></p>
    <p>资料修改成功。</p>
    <p>返回首页,请单击<a href="index.php">这里</a>登录</p>

</div>

</body>
</html>




<?php
/**
 * Created by PhpStorm.
 * User: jiawei
 * Date: 2019/3/25
 */

session_start();

$ID = $_POST['id1'];
$user_name = $_POST['user_name'];
$password = $_POST['password1'];
$question = $_POST['question'];
$answer = $_POST['answer'];
$true_name = $_POST['true_name'];
$sex = $_POST['sex'];
$address = $_POST['address'];
$tel = $_POST['tel'];
$qq = $_POST['qq'];
$email = $_POST['email'];
$authority = $_POST['authority'];
include ('conn.php');
mysqli_query($conn,"UPDATE member SET username='$user_name',
  password='$password',question='$question',answer='$answer',
  truename='$true_name',sex='$sex',address='$address',tel='$tel',
  qq='$qq',email='$email',authority='$authority' WHERE id='$ID'");


?>

12.lostpassword.php(找回密码)

<html>
<head>
    <title>找回密码</title>
    <link rel="stylesheet" href="css/style.css">
</head>
<body>

<div class="login">
    <p><strong>密码查询</strong></p>
    <form name="form1" method="post" action="showquestion.php">
        <p>用户名:<input type="text" name="user_name" id="user_name"></p>
        <p><input type="submit" name="button1" id="button1" value="提 交">
        <input type="reset" name="button2" id="button2" value="重 置"></p>
    </form>


</div>

</body>
</html>

<?php
/**
 * Created by PhpStorm.
 * User: jiawei
 * Date: 2019/3/25

 */

?>

13.showquestion.php(提示问题)

<html>
<head>
    <title>找回密码</title>
    <link rel="stylesheet" href="css/style.css">
</head>
<body>

<div class="login">
    <p><strong>查询问题</strong></p>
    <form name="form1" method="post" action="showpassword.php">
        <p>问题提示:
            <select name="question" id="question" disabled="disabled" style="height:30px;width:200px;line-height: 28px;">
                <option value="0">你的小学名字叫什么?</option>
                <option value="1">你的中学名字叫什么?</option>
                <option value="2">你的大学名字叫什么?</option>
                <option value="3">你的母亲名字叫什么?</option>
                <option value="4">你的父亲名字叫什么?</option>
                <option value="5">你的配偶名字叫什么?</option>
                <?php
                /**
                 * Created by PhpStorm.
                 * User: jiawei
                 * Date: 2019/3/25
                 */
                    $user_name = $_POST['user_name'];
                    require_once ('conn.php');
                    $sql = mysqli_query($conn,"SELECT * FROM member WHERE username='$user_name'");
                    $info = mysqli_fetch_array($sql);
                    if($info == false)
                    {
                        echo "<script>alert('无此用户。');history.back();</script>;";
                        exit;
                    }
                    else
                    {
                        $question = $info['question'];
                        echo "<script>document.getElementById('question').selectedIndex = $question;</script>";
                    }
                ?>
            </select>
        </p>
        <p>问题答案:<input type="text" name="answer" id="answer" style="height: 30px;width: 200px;">
            <input type="hidden" name="user_name" id="user_name" value="<?php echo $user_name;?>"></p>
        <p><input type="submit" name="button1" id="button1" value="提 交">
            <input type="reset" name="button2" id="button2" value="重 置"></p>
    </form>


</div>

</body>
</html>

14.showpassword.php(显示密码)

<html>
<head>
    <title>找回密码</title>
    <link rel="stylesheet" href="css/style.css">
</head>
<body>

<div class="login">
    <p><strong>查询结果</strong></p>
    <p id="user_name">用户名:</p>
    <p id="pwd">密码:</p>
    <p>单击<a href="index.php">这里</a>重新登录。</p>
    <?php
    /**
     * Created by PhpStorm.
     * User: jiawei
     * Date: 2019/3/25
     */

    include ('conn.php');
    $user_name = $_POST['user_name'];
    $answer = $_POST['answer'];
    $sql = mysqli_query($conn,"SELECT * FROM member WHERE username='$user_name'");
    $info = mysqli_fetch_array($sql);
    if($info['answer'] != $answer)
    {
        echo "<script>alert('答案输入错误!');history.back();</script>";
        exit;

    }
    else
    {
        $user_name1 = $info['username'];
        $password1 = $info['password'];
        echo "<script>document.getElementById('user_name').innerText='用户名: $user_name1';
            document.getElementById('pwd').innerText = '密码:$password1';</script>";

    }
    ?>
</div>

</body>
</html>

15.conn.php(数据库连接)

<?php
/**
 * Created by PhpStorm.
 * User: jiawei
 * Date: 2019/3/25
 */

$conn = mysqli_connect("localhost","root","","member");

@ mysqli_set_charset($conn,utf8);

@mysqli_query($conn,utf8);

if(mysqli_connect_errno($conn))
{
    echo "连接MySql数据库失败".mysqli_connect_error()."<br>";
}

?>

16.style.css

.login
{
    width: 300px;
    height: 200px;
    background-color: bisque;
    margin: 20px auto;
    padding: 20px;
}
.login p a
{
    text-decoration: none;
    color: #22276d;

}

.login_tb
{
    width: 98%;
    height:99%;
    border: 1px solid #2d2d2d;
    margin: 0 auto;
    text-align: center;
    color: #333333;
}

.login_tb th
{
    height: 25%;
    line-height: 30px;
}

.login_tb input[type=text]
{
    width: 180px;
    height: 30px;
}

.login_tb input[type=submit], .login_tb input[type=reset]
{
    width: 80px;
    height: 30px;
    border: 1px solid #237a47;
    background-color: #237a47;
    margin-left: 15px;
}

.login_tb a
{
    text-decoration: none;
    color: #22276d;

}

/*----------------------------------------------------------------------*/
.register
{
    width: 600px;
    background-color: #cccccc;
    margin: 10px auto;
    text-align: center;
    box-shadow: 5px 5px 8px #333333;

}

.register_tb
{
    width: 98%;
    border: 1px solid #2e7a5e;
    margin: 5px auto;
    text-align: center;
    color: #2d2d2d;
    border-collapse: collapse;
    padding: 0;
}
.register_tb tr
{
    height: 30px;
    line-height: 30px;

}

.register_tb .tb_alignl
{
    text-align: left;
    text-indent: 20px;
    width: 65%;
    border: 1px solid #2e7a5e;
}

.register_tb .tb_alignr
{
    text-align: right;
    padding-right: 15px;
    width: 35%;
    border: 1px solid #2e7a5e;
}

.register_tb input[type=text]
{
    width: 300px;
    height: 28px;
}
.register_tb select
{
    width: 300px;
    height: 28px;
}

.register_tb caption
{
    font-size: 25px;
    margin: 20px 0;
    font-weight: bold;
    color: #555555;
}

.register_tb input[type=submit], .register_tb input[type=reset]
{
    width: 80px;
    height: 30px;
    border: 1px solid #237a47;
    background-color: #237a47;
    margin-left: 15px;
}

 

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 撸撸猫 设计师:C马雯娟 返回首页