时间:2021-07-01 10:21:17 帮助过:71人阅读
双专业毕业论文做了一个小型企业库存管理系统,使用PHP&mysql组合进行开发。头一次开发稍微大一点的东西,php也是自学的。这里想跟大家一起分享一下
check_login 模块
代码如下:
<!--用户登陆检验模块-->
<?php
session_start();
$workid=$_GET['wid'];//获取工作号
if($workid!=$_SESSION['$workid']||$workid==''){
echo "<script language=javascript>alert('您还没有登陆,无法管理!');location.href='login.php';</script>";
}
?>
function.inc//主要包括数据库连接模块
代码如下:
<?php
function mysql_link($user="admin",$password="admin",$database="systembase"){
$id=mysql_connect("localhost",$user,$password);
if(!$id){
die('Could not connect: ' . mysql_error());
}
if (!mysql_select_db($database,$id)){
die ("Can\'t select_db : " . mysql_error());
}
//改变客户端字符集编码为gb2312
mysql_query("SET NAMES gb2312");
return $id;
}
?>
仓库管理界面storage.php
代码如下:
<!--仓库管理员管理界面-->
2 <?php
3 include "inc/check_login.php";
4 include "inc/function.inc";
5 $id=mysql_link("storage","storage");//建立storage连接
6
7 $query="select * from admin where admin_id='$workid'";//定位仓库
8 $result=mysql_query($query,$id);
9 $info=mysql_fetch_array($result,MYSQL_ASSOC);
$stoid=$info['storage_id'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<LINK href="images/style.css" type=text/css rel=stylesheet>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<title>仓库管理</title>
<style type="text/css">
body{
font-family:Arial,Helvetica,sans-serif; /*设置字体样式*/
font-size:12px;
margin:0px 240px;
height:auto;
width:800px;
border:1px solid #006633;
background-color:rgb(195,245,200);
}
</style>
</head>
<body>
<div id="header" ></div>
<ul id="nav">
<li><a href="logout.php">注 销</a></li>
<?php
echo "<li><a href=input.php?wid=".$workid.">入 库</a></li>";
echo "<li><a href=output.php?wid=".$workid.">出 库</a></li>";
?>
</ul>
<div id="content" align=center>
<div id="man_zone" align=center>
<table width="99%" border="1" align="center" cellpadding="3" cellspacing="1">
<?php
$query="select * from storage where storage_id='$stoid'";//定位仓库信息
$result=mysql_query($query,$id);
if(mysql_num_rows($result)<1){
echo "没有仓库".$stoid;
}else{
$info=mysql_fetch_array($result,MYSQL_ASSOC);
echo "仓库号:".$stoid." 总容量:".$info['storage_cap']." 剩余容量:".$info['storage_lcap']."
仓库地址:".$info['storage_add']." 仓库电话:".$info['storage_tele'];
if (!mysql_select_db("basicbase",$id)){
die ("Can\'t select_db : " . mysql_error());
}
//在basicbase中建立对应仓库货物视图,入库视图以及出库视图
//判断是否存在相关视图,没有的话就新建视图
$query="select * from ".$stoid."_inventory";
if(!mysql_query($query,$id)){
//创建inventory视图
$query="create view ".$stoid."_inventory as
select inventory.goods_id,name,number from inventory,systembase.goods where storage_id=".$stoid." and inventory.goods_id=systembase.goods.goods_id";
if(!mysql_query($query,$id)){
die ("Can\'t create_view_inventory : " . mysql_error());
}
//创建input视图
$query="create view ".$stoid."_input as
select input_id,goods_id,number,time from input where admin_id=".$workid;
if(!mysql_query($query,$id)){
die ("Can\'t create_view_input : " . mysql_error());
}
//创建output视图
$query="create view ".$stoid."_output as
select output_id,goods_id,number,time from output where admin_id=".$workid;
if(!mysql_query($query,$id)){
die ("Can\'t create_view_output : " . mysql_error());
}
}
$query="select * from ".$stoid."_inventory";
$result=mysql_query($query,$id);
if(mysql_num_rows($result)<1){
echo "<br>该仓库目前是空的";
}else{
$totalnum=mysql_num_rows($result);
$pagesize=7;
$page=$_GET["page"];
if(""==$page){
$page=1;
}
$begin=($page-1)*$pagesize;
$totalpage=ceil($totalnum/$pagesize);
echo "<tr>仓库中共有".$totalnum."种货物。";
echo "每页".$pagesize."种,共".$totalpage."页。</tr>";
for($j=1;$j<=$totalpage;$j++){
echo "<a href=storage.php?wid=".$workid."&page=".$j.">[".$j."] </a>";
}
echo "<br>";
$query="select *from ".$stoid."_inventory order by goods_id limit $begin,$pagesize";
$result=mysql_query($query,$id);
$datanum=mysql_num_rows($result);
//echo "<tr><td id=table_title >货物id</td><td id=table_title >货物名称</td><td id=table_title >货物数量</td></tr>";
echo "<tr><td >货物id</td><td >货物名称</td><td >货物数量</td></tr>";
for($i=1;$i<=$datanum;$i++){
$info=mysql_fetch_array($result,MYSQL_ASSOC);
//echo "<tr><td id=table_title >".$info['goods_id']."</td><td id=table_title >".$info['name']."</td><td id=table_title >".$info['number']."</td></tr>";
echo "<tr><td >".$info['goods_id']."</td><td >".$info['name']."</td><td >".$info['number']."</td></tr>";
}
}
}
mysql_close($id);
?>
</table>
</div>
</div>
<div id="footer">版权所有:Freeze&zhaoL <br>E-mail:zhoujiebin15@qq.com</div>
</body>
</html>
代码太多不一一贴了,第一次写碰到很多问题,但不管怎么说程序还是运行起来了