一:代码设计
1.index.php
该页面用于显示管理员的登录和物品的库存。并可以进行订货。
<!--html登录界面-->
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<form action="login.php" method="post">
<fieldset>
<legend>用户登录</legend>
<ul>
<li>
<label>账 户:</label>
<input type="text" name="username">
</li>
<li>
<label>密 码:</label>
<input type="password" name="password">
<li>
<label> </label>
<input type="submit" name="login" value="登录">
</li>
</ul>
</fieldset>
</form>
<!-- php清单显示 -->
<?php
$link = mysqli_connect( 'localhost' , 'root', '' , 'test' );
if (!$link)
{
printf("Can't connect to MySQL Server. Errorcode: %s ", mysqli_connect_error());
exit;
}
else
{
echo'数据库连接成功';
}
mysqli_query($link,'set names utf8'); //解决中文乱码的问题
echo '
<fieldset>
<legend>数据清单</legend>';
if ($result = mysqli_query($link, 'SELECT * FROM woods ')) {
while( $row = mysqli_fetch_assoc($result) )
{
?>
<ul>
<li>
<form action="request.php" method="post">
<input name="name" readonly="readonly" value="<?php echo "{$row['name']}"; ?>">
<?php echo ' : ';?>
<input name="num" readonly="readonly" value="<?php echo "{$row['num']}"; ?>">
<input type="submit" name="request" value="请求">
</form>
</li>
</ul>
<?php
}
}
?>
2.login.php
用于对管理员的登录进行验证
<?php
header('Content-type:text/html; charset=utf-8');
if (isset($_POST['login'])) {
# 接收用户的登录信息
$username = trim($_POST['username']);
$password = trim($_POST['password']);
if (($username == '') || ($password == '')) {
// 若为空,视为未填写,提示错误,并3秒后返回登录界面
header('refresh:3; url=login.html');
echo "用户名或密码不能为空,系统将在3秒后跳转到登录界面,请重新填写登录信息!";
exit;
}
$link = mysqli_connect( 'localhost' , 'root', '' , 'test' );
if (!$link)
{
printf("Can't connect to MySQL Server. Errorcode: %s ", mysqli_connect_error());
exit;
}
else
{
}
mysqli_query($link,'set names utf8');
if ($result = mysqli_query($link, 'SELECT * FROM user '))
{
while( $row = mysqli_fetch_assoc($result) ){
if( ($username == $row['user'] ) || ($password == $row['passwd'] ) ){
header('refresh:0;url=main.php');
exit();
}
else{
echo "用户名或密码错误,系统将在3秒后跳转到登录界面,请重新填写登录信息!";
header('refresh:3; url=index.php');
exit();
}
}
mysqli_free_result($result);
}
else{
echo "用户名或密码错误,系统将在3秒后跳转到登录界面,请重新填写登录信息!";
header('refresh:3; url=index.php');
exit();
}
mysqli_close($link);
}
?>
3.repuest.php
用于订货表单的显示
<?php
header('Content-type:text/html; charset=utf-8');
//接受用户的选择
if (isset($_POST['request'])) {
$name = trim($_POST['name']);
?>
<!-- 用户请求表-->
<form action="request2.php" method="post">
<fieldset>
<legend>请求清单</legend>
<ul>
<li>
<lable>角色名</lable>
<?php echo ' : ';?>
<input name="peoplename" value="">
</li>
<li>
<lable>物品名</lable>
<?php echo ' : ';?>
<input type="text" name="name" readonly="readonly" value="<?php echo $name;?>">
</li>
<li>
<lable>数   目</lable>
<?php echo ' : ';?>
<input type="text" name="num" value="">
</li>
<li>
<input type="submit" name="request" value="请求">
</li>
</ul>
</fieldset>
<?php
}
?>
4.request2.php
用于让订货信息输入数据库
<?php
header('Content-type:text/html; charset=utf-8');
if (isset($_POST['request'])) {
# 接收用户的请求信息
$name = trim($_POST['name']);
$peoplename = trim($_POST['peoplename']);
$num = trim($_POST['num']);
if(($name=="") || ($peoplename=="") || ($num=="") ){
header('refresh:3; url=index.php');
echo "人物与数目不能为空,系统将在3秒后跳转到首页!";
exit;
}
if($num<=0){
header('refresh:3; url=index.php');
echo "数据输入不合法,系统将在3秒后跳转到首页!";
exit;
}
$link = mysqli_connect( 'localhost' , 'root', '' , 'test' );
if (!$link)
{
printf("Can't connect to MySQL Server. Errorcode: %s ", mysqli_connect_error());
exit;
}
else
{
}
mysqli_query($link,'set names utf8');
$peopledid=1;
$rest="insert into needs values('','$peoplename','$name',$num,now(),$peopledid)";
$result= mysqli_query($link,$rest);
if ($result) {
echo"请求成功,系统将在3秒后跳转到首页";
header('refresh:3; url=index.php');
}
5.mian.php
显示出货信息和库存信息
<!--请求清单显示-->
<?php
header('Content-type:text/html; charset=utf-8');
$link = mysqli_connect( 'localhost' , 'root', '' , 'test' );
if (!$link) {
printf("Can't connect to MySQL Server. Errorcode: %s ", mysqli_connect_error());
exit;
}
else{
//echo'数据库连接成功';
}
mysqli_query($link,'set names utf8'); //解决中文乱码的问题
echo '
<fieldset>
<legend>申请清单</legend>
<table>
<tr>
<td>编号</td>
<td>申请人</td>
<td>物品</td>
<td>数目</td>
<td>申请时间</td>
<td>是否完成</td>
</tr>
';
if ($result = mysqli_query($link, 'SELECT * FROM needs ')) {
while( $row = mysqli_fetch_assoc($result) ){
?>
<tr>
<form action="chuhuo.php" method="post">
<td><input type="text" size="10" readonly="readonly" name="id" value="<?php echo $row['id'];?>"></td>
<td><input type="text" size="10" readonly="readonly" name="peoplename" value="<?php echo $row['peoplename'];?>"></td>
<td><input type="text" size="10" readonly="readonly" name="name" value="<?php echo $row['name'];?>"></td>
<td><input type="text" size="10" readonly="readonly" name="num" value="<?php echo $row['num'];?>"></td>
<td><input type="text" size="15" readonly="readonly" name="peopledate" value="<?php echo $row['peopledate'];?>"></td>
<td><input type="text" size="10" readonly="readonly" name="peopledid" value="<?php echo $row['peopledid'];?>"></td>
<td><input type="submit" name="queding" value="确定"></td>
<td><input type="button" onclick='location.href=("index.php")' name="" value="首页"></td>
</form>
</tr>
<?php
}
mysqli_free_result($result);
echo '</table></fieldset>';
}
mysqli_close($link);
?>
<!--补货显示-->
<?php
$link = mysqli_connect( 'localhost' , 'root', '' , 'test' );
if (!$link) {
printf("Can't connect to MySQL Server. Errorcode: %s ", mysqli_connect_error());
exit;
}
else{
//echo'数据库连接成功';
}
mysqli_query($link,'set names utf8'); //解决中文乱码的问题
echo '
<fieldset>
<legend>库存清单</legend>
<table>
<tr>
<td>编号</td>
<td>物品</td>
<td>数目</td>
</tr>
';
if ($result = mysqli_query($link, 'SELECT * FROM woods ')) {
while( $row = mysqli_fetch_assoc($result) ){
?>
<tr>
<form action="buhuo.php" method="post">
<td><input type="text" size="10" readonly="readonly" name="id" value="<?php echo $row['id'];?>"></td>
<td><input type="text" size="10" readonly="readonly" name="name" value="<?php echo $row['name'];?>"></td>
<td><input type="text" size="10" readonly="readonly" name="num" value="<?php echo $row['num'];?>"></td>
<td><input type="submit" name="buhuo" value="补货"></td>
<td><input type="button" onclick='location.href=("index.php")' name="" value="首页"></td>
</form>
</tr>
<?php
}
mysqli_free_result($result);
echo '</table></fieldset>';
}
mysqli_close($link);
?>
6.chuhuo.php
用于出货的操作,当货物不足时,无法出货,已出货的物品后面出货信息显示为0,没有出货则为1
<!--请求清单操作模块-->
<?php
header('Content-type:text/html; charset=utf-8');
if (isset($_POST['queding'])) {
$peoplename = trim($_POST['peoplename']);
$name = trim($_POST['name']);
$num = trim($_POST['num']);
$peopledid = trim($_POST['peopledid']);
$id = trim($_POST['id']);
$link = mysqli_connect( 'localhost' , 'root', '' , 'test' );
if (!$link) {
printf("Can't connect to MySQL Server. Errorcode: %s ", mysqli_connect_error());
exit;
}
else{
//echo'数据库连接成功';
}
mysqli_query($link,'set names utf8'); //解决中文乱码的问题
$result = mysqli_query($link, "SELECT * FROM woods WHERE id='$id'");
$row = mysqli_fetch_assoc($result) ;
if($peopledid==0){
echo '单子已完成';
header('refresh:0; url=main.php');
}
else{
if($row['num']>=$num){
$numcha=$row['num']-$num;
$peopledid=0;
$result1 = mysqli_query($link, "update woods set num='$numcha' where name= '$name' ");
$result2 = mysqli_query($link, "update needs set peopledid='$peopledid' where id='$id' ");
header('refresh:3; url=main.php');
echo '出货成功,3秒后返回管理员界面' ;
}
else{
header('refresh:3; url=main.php');
echo $peoplename,'货源不足,无法出货,3秒后返回管理员界面';
}
}
mysqli_close($link);
}
?>
7.buhuo.php
用于填写补货数目
<!--补货响应-->
<?php
header('Content-type:text/html; charset=utf-8');
//接受用户的选择
if (isset($_POST['buhuo'])) {
$name = trim($_POST['name']);
$id = trim($_POST['id']);
?>
<fieldset>
<legend>补货清单</legend>
<table >
<!-- 管理员补货表-->
<tr><td>物品编号</td><td>物品名称</td><td>补货数目</td><tr>
<form action="buhuo2.php" method="post">
<tr>
<td><input name="id" readonly="readonly" value="<?php echo $id; ?>"></td>
<td><input type="text" size="6" readonly="readonly" name="name" value="<?php echo "{$name}";?>"></td>
<td><input type="text" size="6" name="num" value=""></td>
<td><input type="submit" name="buhuo" value="确定补货"></td>
<tr/>
</form>
</table>
</fieldset>
<?php
}
?>
8.buhuo2.php
用于对补货进行操作
<!--补货操作-->
<?php
header('Content-type:text/html; charset=utf-8');
if (isset($_POST['buhuo'])) {
$name = trim($_POST['name']);
$num = trim($_POST['num']);
$id = trim($_POST['id']);
$link = mysqli_connect( 'localhost' , 'root', '' , 'test' );
if (!$link) {
printf("Can't connect to MySQL Server. Errorcode: %s ", mysqli_connect_error());
exit;
}
else{
//echo'数据库连接成功';
}
mysqli_query($link,'set names utf8'); //解决中文乱码的问题
$result = mysqli_query($link, "select * from woods WHERE id='$id' ");
$row = mysqli_fetch_assoc($result) ;
if($num=="" || $id=="" || $name=="" || $num<=0){
echo '数据错误,3秒后返回管理员界面';
header('refresh:3;url=main.php');
exit;
}
echo $id;
echo $num,$row['num'];
$num2=$num+$row['num'];
echo $num2;
$result1 = mysqli_query($link, "update woods set num='$num2' where name= '$name' ");
if($result1){
echo'补货成功,3秒后返回管理员界面';
header('refresh:3;url=main.php');
exit;
}
else{
echo $name,'补货失败,3秒后返回管理员界面';
header('refresh:3;url=main.php');
exit;
}
mysqli_free_result($result);
}
?>
二:数据库设计
1.user表
由用户名:user ,密码: passwd组成。
user,主键,类型为char,长度根据需求自选,个人为6。
passwd,类型为char,长度根据需求自选,个人为6。
user表用于存储管理员账号
2.woods表
由物品id:id ,物品名称: name,物品数目:num组成。
id,主键,自增,类型为int ,长度默认。
name,类型char,长度20。
num,类型int,长度默认。
用于存储已有物品
3.needs表
由物品id:id ,物品名称: name,申请人:peoplename,物品数目:num,申请时间:peopledate,是否出货:peopledid组成。
id,主键自增,类型int,长度默认。
name,类型char,长度20。
peoplename,类型char,长度20。
num,类型int,长度默认。
peopledate,类型datetime。
peopledid,类型int,长度默认。