目录
一.建立MySQL数据库
1.定制app开发我使用的是xampp,定制app开发在浏览器地址栏输入http://localhost//phpmyadmin
注意:定制app开发端口号默认是80端口,也就是http://localhost:80//phpmyadmin,定制app开发如果你改了你的端口号注意更改
2.定制app开发点击新建数据库(库名是itcast52)两个表明,book52(定制app开发增删改查用)user52(定制app开发登录注册用)
定制app开发以下是数据库的文件,定制app开发建立一个记事本,把代码粘贴上去,点击保存,把后缀从text改成sql,然后在数据库建立一个itcast52数据库,在数据库里面导入sql文件即可(数据库就完毕了)
- -- phpMyAdmin SQL Dump
- -- version 3.5.2.2
- -- http://www.phpmyadmin.net
- --
- -- 主机: 127.0.0.1
- -- 生成日期: 2022 年 05 月 16 日 05:24
- -- 服务器版本: 5.5.27
- -- PHP 版本: 5.4.7
-
- SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
- 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 utf8 */;
-
- --
- -- 数据库: `itcast52`
- --
-
- -- --------------------------------------------------------
-
- --
- -- 表的结构 `book52`
- --
-
- CREATE TABLE IF NOT EXISTS `book52` (
- `id` varchar(20) NOT NULL,
- `name` varchar(20) CHARACTER SET utf8 COLLATE utf8_estonian_ci NOT NULL,
- `price` varchar(20) NOT NULL,
- `data` varchar(20) NOT NULL,
- `type` varchar(20) NOT NULL
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
- --
- -- 转存表中的数据 `book52`
- --
-
- INSERT INTO `book52` (`id`, `name`, `price`, `data`, `type`) VALUES
- ('003', 'csdn', '55', '2025-11-6', '数据库设计'),
- ('012', '雕塑', '17777', '20255-5-6', '雕塑'),
- ('066', '固化剂', '255', '2001-09-06', '添加剂'),
- ('3119050152', '张修博', '999999', '2000-01-12', '人');
-
- -- --------------------------------------------------------
-
- --
- -- 表的结构 `user52`
- --
-
- CREATE TABLE IF NOT EXISTS `user52` (
- `account` char(100) NOT NULL,
- `username` char(100) NOT NULL,
- `sex` char(100) NOT NULL,
- `age` char(100) NOT NULL,
- `address` char(100) NOT NULL,
- `mail` char(100) NOT NULL,
- `password` char(100) NOT NULL,
- `number` char(100) NOT NULL
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
- --
- -- 转存表中的数据 `user52`
- --
-
- INSERT INTO `user52` (`account`, `username`, `sex`, `age`, `address`, `mail`, `password`, `number`) VALUES
- ('3119050152', '张修博', '男', '21', '河南商丘', '3119050152@qq.com', '3119050152', '3119050152');
-
- /*!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 */;
二.链接数据库文件(conn.php)
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>conn文件</title>
- </head>
-
- <body>
- <?php
-
- $mysql_server_name = 'localhost'; //改成自己的mysql数据库服务器
- $mysql_username = 'root'; //改成自己的mysql数据库用户名
- $mysql_password = ''; //改成自己的mysql数据库密码
- $mysql_database = 'itcast52'; //改成自己的mysql数据库名
- $conn=mysqli_connect($mysql_server_name,$mysql_username,$mysql_password,$mysql_database); //连接数据库
- //连接数据库错误提示
- mysqli_query($conn, 'set names utf8');
- mysqli_query($conn, 'set character set utf8');
- if (mysqli_connect_errno($conn))
- {
- die("连接 MySQL 失败: " . mysqli_connect_error());
- }
- ?>
- </body>
- </html>
三.前端登录页面(log.php)
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>无标题文档</title>
- </head>
- <style type="text/css">
- #aaa{width: 300px;
- height: 30px;}
-
- </style>
-
- <body>
- <center>
- <h2>登录界面</h2>
- <form method="POST" action="log_ok.php">
- 账号 :<input id="aaa" type="text" name="uname" placeholder="用户名" />
- <br /><br/>
- 密码 :<input id="aaa"type="password" name="pwd" placeholder="密码" />
- <br />
- <input type="submit" >
- <input type="reset"> <a href="register.php">注册账号</a>
-
- </form>
- </center>
- </body>
- </html>
四.登录实现页面(log_ok.php)
- <?php
- //------文件编码格式,为了显示中文--------
- header("content-type:text/html; charest=UTF-8");
-
- //-------收受web的传值-------
- $uname=$_POST["uname"];
- $pwd=$_POST["pwd"];
-
- //-----链接mysql数据库---
- include("conn.php");
-
- //----免除一些警告-------
- error_reporting(0);
-
- //-------启动session------
- session_start();
-
- //判断$uname与$pwd是否为空值-->true 返回上一步-->false 执行数据库查询,并且给session赋值
- if(!($uname && $pwd)){
- echo"<script>alert('输入的账号或密码为空!请重新输入账号和密码');history.go(-1);</script>";
- }else{
- $sqlstr ="SELECT * FROM user52 WHERE (account='$uname') AND (password='$pwd')";
-
- $result = $conn->query($sqlstr);
- }
- if($result->num_rows > 0){
- $_SESSION["user"]=$uname;
- echo"<script>alert('登录成功,即将转到主页面');location='index1.php'</script>";
-
- }else{
- echo"<script>alert('密码或者账号错误,登录失败,请重新输入账号和密码');history.go(-1);</script>";
- }
-
- ?>
五.前端注册页面(register.php)
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>无标题文档</title>
- </head>
- <style type="text/css">
- .aaa{width: 300px;
- height: 30px;}
-
- </style>
- <style type="text/javascript">
- </style>
-
- <body>
- <?php
- $a=mt_rand(333333,999999999);
- ?>
-
- <center>
- <h2>注册界面</h2>
- <form method="post" name="from1" action="register_ok.php"><!-- 在数据库中id是自动增长列 -->
- 账号: <input name="id" class="aaa" type="text" value="<?php echo"$a";?>"><br/><br/>
- 姓名: <input class="aaa" type="text" name="username"><br/><br/>
- 性别: <input class="aaa" type="text" name="sex"><br/><br/>
- 年龄: <input class="aaa" type="text" name="age"><br/><br/>
- 地址: <input class="aaa" type="text" name="address"><br/><br/>
- 邮箱: <input class="aaa" type="text" name="mail"><br/><br/>
- 密码: <input class="aaa" type="text" name="password"><br/><br/>
- 确认 密码: <input class="aaa" type="text" name="repsw"><br/><br/>
- 手机号: <input class="aaa"type="text" name="number"><br/><br/>
-
-
- <input type="reset"name="reset" value="重置">
- <input type="submit"name="submit" value="注册" onClick="myfunction">
- <a href="log.php"><< 返回上一页</a>
- <a href="register.php">点击注册</a>
- </form>
- </body>
- </html>
六.注册实现界面(register_ok.php)
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>无标题文档</title>
- </head>
-
- </body>
-
- <body>
- <?php
- include_once("conn.php");
- header("content-type:text/html; charest=UTF-8");//文件编码格式
- session_start();
-
-
- $id=$_POST['id'];
- $username=$_POST['username'];
- $sex=$_POST['sex'];
- $age=$_POST['age'];
- $address=$_POST['address'];
- $mail=$_POST['mail'];
- $password=$_POST['password'];
- $repsw=$_POST['repsw'];
- $number=$_POST['number'];
-
-
-
-
- if(!($id and $username and $sex and $age and $address and $mail and $password and $number and $repsw )){
- echo"<script>alert('输入值不许为空');history.go(-1);</script>";
- }else{
- if(!($repsw==$password)){
- echo"<script>alert('两次密码不一致');history.go(-1);</script>";
- }else{
- $sql = "SELECT * FROM user52 WHERE (account='$id')";//在数据库中找相应信息!
- $res = $conn->query($sql);
- //判断结果集的记录数是否大于0
-
- if ($res->num_rows > 0){
- echo"<script>alert('已经有相同账号,请您换个账号进行注册');history.go(-1);</script>";
- }else{
- $_SESSION['user']=$id;
- $sqlstr1="insert into user52 values('".$id."','".$username."','".$sex."','".$age."','".$address."','".$mail."','".$password."','".$number."')";
- //执行sql insert语句 把用post引用的变量接入到register中
- $result = mysqli_query($conn,$sqlstr1);//承接结果集
-
- if($result){
- echo"<script>alert('注册成功');location='index1.php'</script>";
- }else{
- echo"<script>alert('注册失败');history.go(-1);</script>";
- }
- }
- }
-
- }
-
-
- ?>
- </body>
- </html>
七.主页面(index1.php)增删改查中的 查
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>图书管理系统</title>
- </head>
-
- <body>
- <?php
- error_reporting(0);
- session_start();
- include("conn.php");
- ?>
- <center>
- <table width="799" height="247" border="1" cellpadding="0" cellspacing="0">
- <tr>
- <td height="220" background="1.jpg"> </td>
- </tr>
- <tr>
- <td>
- <table width="100%" height="27" border="1" cellpadding="0" cellspacing="0">
- <tr bgcolor="#9791C2">
- <td width="149" align="center" valign="middle"><b>
- <?php
- echo date("Y-m-d")."";
- ?>
- </b></td>
- <td width="130" align="center" valign="middle"><a href="index1.php" class="s">浏览目录</a></td>
- <td width="130" align="center" valign="middle"><a href="index_ok.php" class="s">添加图书</a></td>
- <td width="130" align="center" valign="middle"><a href="index-select.php" class="s">简单查询</a></td>
- <td width="130" align="center" valign="middle"><a href="update1.php" class="s">删除图书</a></td>
- <td width="130" align="center" valign="middle"><a href="delete.php" class="s">修改图书</a></td>
- <td width="130" align="center" valign="middle"><a href="back.php" class="s">退出系统</a></td>
- <td width="130" align="center" valign="middle"><a href="index1.php" class="s"><?php if(!($_SESSION['user']))
- echo'session为空';
- else{
- echo"欢迎 :";
- echo $_SESSION['user'];
-
- } ?></a></td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- <table width="799" border="0" cellpadding="0" cellspacing="0">
- <tr>
- <tr align="center" valign="middle">
- <?php
- include_once("conn.php");
- ?>
- <table width="52.5%" border="1" cellpadding="0" cellspacing="0">
- <tr bgcolor="#F7E0A3">
- <td width="3%" height="25" class="top" align="center">id</td>
- <td width="10%" class="top" align="center">图书名称</td>
- <td width="10%" class="top" align="center">价格</td>
- <td width="10%" class="top" align="center">出版日期</td>
- <td width="5%" class="top" align="center">类型</td>
- </tr>
- <?php
- $result = mysqli_query($conn,"select * from book52 ");
- /*$sums = mysqli_num_rows($result);
- echo $nums;*/
- while($myrows = mysqli_fetch_array($result)){
- ?>
- <tr>
- <td align="center"><span class="STYLE2"><?php echo $myrows['id'];?></span></td>
- <td align="center"><span class="STYLE2"><?php echo $myrows['name'];?></span></td>
- <td align="center"><span class="STYLE2"><?php echo $myrows['price'];?></span></td>
- <td align="center"><span class="STYLE2"><?php echo $myrows['data'];?></span></td>
- <td align="center"><span class="STYLE2"><?php echo $myrows['type'];?></span></td>
- </tr>
-
- <?php
-
- }
- ?>
- </table>
- </tr>
- </tr>
- </table>
- </center>
- <?php
- $sum = mysqli_num_rows($result);
- echo $sum;
- ?>
- </body>
- </html>
八.添加图书(index_ok.php)增删改查中的 增
这个代码包含了实现的代码!
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>添加数据</title>
- </head>
-
- <body>
- <?php
- error_reporting(0);
- session_start();
- include("conn.php");
- ?>
- <center>
- <table width="799" height="247" border="1" cellpadding="0" cellspacing="0">
- <tr>
- <td height="220" background="1.jpg"> </td>
- </tr>
- <tr>
- <td>
- <table width="100%" height="27" border="1" cellpadding="0" cellspacing="0">
- <tr bgcolor="#9791C2">
- <td width="149" align="center" valign="middle">
- <b>
- <?php
- echo date("Y-m-d")."";
- ?>
- </b>
- </td>
- <td width="130" align="center" valign="middle"><a href="index1.php" class="s">浏览目录</a></td>
- <td width="130" align="center" valign="middle"><a href="index_ok.php" class="s">添加图书</a></td>
- <td width="130" align="center" valign="middle"><a href="index-select.php" class="s">简单查询</a></td>
-
- <td width="130" align="center" valign="middle"><a href="back.php" class="s">退出系统</a></td>
- <td width="130" align="center" valign="middle"><a href="index1.php" class="s"><?php if(!($_SESSION['user']))
- echo'session为空';
- else{
- echo"欢迎 :";
- echo $_SESSION['user'];
-
- } ?></a></td>
- </tr>
- </table>
-
-
- </td>
- </tr>
- </table>
-
-
-
- <form method="post" name="form1" action="index_ok.php">
-
- 编号 : <input type="text" name="id" ></input><br/><br/>
- 姓名 : <input type="text" name="name"></input><br/><br/>
- 价格 : <input type="text" name="price"></input><br/><br/>
- 日期 : <input type="text" name="data"></input><br/><br/>
- 类型 : <input type="text" name="type"></input><br/><br/>
- <input type="reset" name="5" value="重置"></input>
- <input type="submit" name="6" value="提交"></input>
-
- </form>
- <?php
- error_reporting(0);
- header("content-type:text/html; charest=UTF-8");//文件编码格式
- include_once("conn.php");//连接数据库文件
- $a=$_POST["id"];
- $b=$_POST["name"];
- $c=$_POST["price"];
- $d=$_POST["data"];
- $e=$_POST["type"];
- //把input中的namejie
- if(!($a and $b and $c and $d and $e)){
- echo"<script>alter('输入值不许为空');history.go(-1);</script>";//判断变量名是否为空值
-
- }else{
-
- $sqlstr1="insert into book52 values('".$a."','".$b."','".$c."','".$d."','".$e."')";
-
- //执行sql insert语句 把用post引用的变量接入到bookable中
-
- $result = mysqli_query($conn,$sqlstr1);//承接结果集
-
- if($result){
- echo"<script>alter('添加成功');location='index1.php'</script>";
- }else{
- echo"<script>alter('添加失败');history.go(-1);</script>";
- }
- }
- ?>
- </center>
- </body>
- </html>
九.修改和删除页面(index-select.php)
这个页面包含了两个功能 修改 和 删除 但是 功能实现 在另外两个页面里
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>简单查询</title>
- </head>
-
- <body>
- <?php
- error_reporting(0);
- session_start();
- include("conn.php");
-
- ?>
- <center>
- <table width="799" height="247" border="1" cellpadding="0" cellspacing="0">
- <tr>
- <td height="220" background="1.jpg"> </td>
- </tr>
- <tr>
- <td>
- <table width="100%" height="27" border="1" cellpadding="0" cellspacing="0">
- <tr bgcolor="#9791C2">
- <td width="149" align="center" valign="middle"><b>
- <?php
- echo date("Y-m-d")."";
- ?>
- </b></td>
- <td width="130" align="center" valign="middle"><a href="index1.php" class="s">浏览目录</a></td>
- <td width="130" align="center" valign="middle"><a href="index_ok.php" class="s">添加图书</a></td>
- <td width="130" align="center" valign="middle"><a href="index-select.php" class="s">简单查询</a></td>
-
- <td width="130" align="center" valign="middle"><a href="back.php" class="s">退出系统</a></td>
- <td width="130" align="center" valign="middle"><a href="index1.php" class="s"><?php if(!($_SESSION['user']))
- echo'session为空';
- else{
- echo"欢迎 :";
- echo $_SESSION['user'];
-
- } ?></a></td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- <table width="799" border="0" cellpadding="0" cellspacing="0">
- <tr>
- <tr align="center" valign="middle">
- <?php
- include_once("conn.php");
- ?>
- <table width="52.5%" border="1" cellpadding="0" cellspacing="0">
- <tr bgcolor="#F7E0A3">
- <td width="3%" height="25" class="top" align="center">id</td>
- <td width="10%" class="top" align="center">图书名称</td>
- <td width="10%" class="top" align="center">价格</td>
- <td width="10%" class="top" align="center">出版日期</td>
- <td width="5%" class="top" align="center">类型</td>
- <td width="5%" class="top" align="center">芜湖</td>
- </tr>
- <?php
-
- header("content-type:text/html; charest=UTF-8");//文件编码格式
- include_once("conn.php");//连接数据库文件
-
- $sqlstr="select * from book52 order by id ";//通过把sql语句放到变量值中 来执行php
-
- $result = mysqli_query($conn,$sqlstr);//承接结果集 一般来说结果集之后会被用在循环中例如index_ok.php ,或者遍历输出数据库中的值例如index1.php
-
- while($rows= mysqli_fetch_row($result)){
-
- ?>
- <tr>
- <td align="center"><span class="m_td"><?php echo $rows[0];?></span></td>
- <td align="center"><span class="m_td"><?php echo $rows[1];?></span></td>
- <td align="center"><span class="m_td"><?php echo $rows[2];?></span></td>
- <td align="center"><span class="m_td"><?php echo $rows[3];?></span></td>
- <td align="center"><span class="m_td"><?php echo $rows[4];?></span></td>
- <td align="center" class="m_td">
- <a href =update.php?action=update&id=<?php echo $rows[0]?>>修改</a>/
- <a href =delete.php?action=delete&id=<?php echo $rows[0]?>>删除</td>
- </tr>
-
- <?php
-
- }
- ?>
-
- </table>
- </tr>
- </tr>
- </table>
- </center>
-
-
- </body>
- </html>
十.修改图书(update.php)
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>更改文档</title>
- </head>
-
- <body>
-
- <?php
- error_reporting(0);
- include_once("conn.php");//连接数据库文件
- if($_GET['action']=="update"){
-
- $sqlstr="select * from book52 where id =".$_GET['id']; //".$_GET['id'];没看懂
- $result = mysqli_query($conn,$sqlstr);//承接结果集 一般来说结果集之后会被用在循环中例如index_ok.php ,或者遍历输出数据库中的值例如index1.php
- $rows = mysqli_fetch_row($result); //枚举数组
-
-
- ?>
-
-
- <form method="post" name="intForm" action="update_ok.php">
-
- 姓名 : <input type="text" name="name" value="<?php echo $rows[1]; ?>"></input><br/><br/>
- 价格 : <input type="text" name="price" value="<?php echo $rows[2]; ?>"></input><br/><br/>
- 日期 : <input type="text" name="data" value="<?php echo $rows[3]; ?>"></input><br/><br/>
- 类型 : <input type="text" name="type" value="<?php echo $rows[4]; ?>"></input><br/><br/>
- <input type="hidden" name="action"value="update"></input>
- <input type="hidden" name="id" value="<?php echo $rows[0] ?>"></input>
- <input type="reset" name="Reset" value="重置">
- <input type="submit" name="Submit" value="提交">
-
-
- </form>
-
- <?php
- }
- ?>
-
- </body>
- </html>
十一.修改成功页面(update_ok.php)
这个项目的实现是 地址栏传参数,不会的同学可以去看下资料就差不多会了
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>无标题文档</title>
- </head>
-
- <body>
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>更新数据</title>
- </head>
- <body>
- <?php
- header("Content-type:text/html; charest=UTF-8");//编码方式
-
- include_once("conn.php");//连接数据库
- $a=$_POST["id"];
- $b=$_POST["name"];
- $c=$_POST["price"];
- $d=$_POST["data"];
- $e=$_POST["type"];
- if($_POST['action'] == "update"){
- if(!( $b and $c and $d and $e)){
- echo "输入不允许为空"; //返回上一页 或者使用alert
- }else{
- $sqlstr="update book52 set name='".$b."',price='".$c."',data='".$d."',type='".$e."' where id=".$a; //定义更新语句
-
- //如果查询所有后面属性可以省略,一一对应
- $result = mysqli_query($conn,$sqlstr);
-
-
- if($result){
- echo"修改成功,点击<a href='index1.php'>这里</a>查看";
- }else{
- echo"修改失败.<br>$sqlstr";
- }
- }
- }
- ?>
- </body>
- </html>
- </body>
- </html>
十二.删除页面(delete.php)
包含了删除的功能
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>无标题文档</title>
- </head>
-
- <body>
- <?php
- header("Content-type:text/html; charest=UTF-8");//编码方式
- // 处理删除操作的页面
- include_once("conn.php");
- if($_GET['action']=="delete"){
- $sqlstr1="delete from book52 where id =".$_GET['id'];
- $result=mysqli_query($conn,$sqlstr1);
-
-
- if($result){
- echo"删除成功";
- }else{
- echo"删除失败";
- }
- }
-
- ?>
- </body>
- </html>
十三.退出系统(back.php)
这个代码就是清除的值,并且返回到登陆页面
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>无标题文档</title>
- </head>
-
- <body>
- <?php
- session_start();
- session_unset();
- session_destroy();
- echo"<script>alert('您已经退出系统,请重新登录');location='log.php'</script>";
-
- ?>
- </body>
- </html>
总结:由于仅仅是实现了该有的功能,所以页面不是太美观,有时间的同学可以仔细改一下,如果同学们有什么问题或者我写错了什么,可以在评论区发言,我看到会回复的,共同学习!勉励!!