说明:代码来源《PHP和MySQL Web应用开发》一书,还有就是代码有些是经过修改的,经过我的测验全部都可以用。

 

本示例的数据库脚本   执行语句:  source d:\test\2shou.sql;

复制代码
CREATE DATABASE IF NOT EXISTS 2shou
COLLATE 'gb2312_chinese_ci';

USE 2shou;
CREATE TABLE IF NOT EXISTS Bulletin (
    Id INT  AUTO_INCREMENT  PRIMARY KEY,
    Title varchar(50), 
    Content varchar(1000),
    PostTime datetime,
    Poster  varchar(50)
);

CREATE TABLE IF NOT EXISTS  GoodsType (
    TypeId  INT  AUTO_INCREMENT  PRIMARY KEY,
    TypeName VARCHAR(100)  NOT NULL
);

CREATE TABLE IF NOT EXISTS Goods (
    GoodsId INT  AUTO_INCREMENT  PRIMARY KEY,
    TypeId INT, 
    SaleOrBuy TINYINT,
    GoodsName VARCHAR(50),
    GoodsDetail VARCHAR(1000),
    ImageURL VARCHAR(100),
    Price VARCHAR(50),
    StartTime  DATETIME,
    OldNew  VARCHAR(50),
    Invoice  VARCHAR(50),
    Repaired  VARCHAR(50),
    Carriage  VARCHAR(50),
    PayMode  VARCHAR(50),
    DeliverMode  VARCHAR(50),
    IsOver  TINYINT,
    OwnerId  VARCHAR(50),
    ClickTimes  INT
);

CREATE TABLE IF NOT EXISTS Users (
    UserId    VARCHAR(50),
    UserPwd    VARCHAR(50),
    Name    VARCHAR(50),
    Sex    TINYINT,
    Address    VARCHAR(500),
    Postcode    VARCHAR(50),
    Email    VARCHAR(50),
    Telephone    VARCHAR(100),
    Mobile    VARCHAR(50),
    UserType TINYINT
);
INSERT INTO Users VALUES('Admin', '111111', 'Admin', 1, '', '', '', '', '', 1);
复制代码

 style.CSS  CSS样式代码

BODY
{
    FONT-FAMILY: 宋体;
    FONT-SIZE: 9pt
}
TD
{
    FONT-SIZE: 9pt
}
P
{
    FONT-SIZE: 9pt
}
LI
{
    FONT-SIZE: 9pt
}
BigFont
{
    FONT-SIZE: 9pt
}
A:link
{
    COLOR: blue;
    TEXT-DECORATION: none
}
A:visited
{
    COLOR: blue;
    TEXT-DECORATION: none
}
A:hover
{
    TEXT-DECORATION: underline
}
INPUT
{
    FONT-SIZE: 9pt
}
SELECT
{ FONT-SIZE:9pt}
TEXTAREA{ FONT-SIZE:9pt}
View Code

 


 

1.BulletinView.php    用于显示公告信息的页面

<html>
<head>
<title>公告</title>
<link href=style.css rel=STYLESHEET type=text/css>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312"><style type="text/css">
<!--
body,td,th {
    color: #D4D0C8;
}
body {
    background-color: #FFFFFF;
}
.STYLE1 {color: #000000}
-->
</style></head>
<body>

<?PHP
  include('Class\Bulletin.php');
  //从数据库中取得此公告信息
  //读取参数id
  $id=$_GET["id"];
  //根据参数id读取指定的公告信息
  $obj = new Bulletin();
  $results = $obj->GetBulletinInfo($id);
  //如果记录集为空,则显示没有此公告
  if($obj->Id==0)
  {
    exit("没有此公告");
  }
  else
  {
?>
<form name="myform" method="POST" action="">
        <table border="0" width="100%" cellspacing="1">
          <tr>
            <td width="100%" bgcolor="#FFFFFF"><span class="STYLE1">公告标题
            <input type="text" readonly="true" name="title" size="20" value="<?PHP   echo($obj->Title); ?>">
            </span></td>
          </tr>
          <tr>
            <td width="100%" bgcolor="#FFFFFF"><span class="STYLE1">公告内容</span></td>
          </tr>
          <tr>
            <td width="100%" bgcolor="#FFFFFF"><textarea rows="12" readonly="readonly" name="content" cols="55"><?PHP echo($obj->Content); ?></textarea></td>
          </tr>
  </table>
<?PHP 
} 
?>
</form>
<?PHP
 $obj=null;
?>
</body>
</html>
View Code

2.GoodsView.php     用于显示商品信息的页面

<html>
<head>
<title>查看商品信息</title>
<link href=style.css rel=STYLESHEET type=text/css>
</head>
<body>
<center>
<?PHP 
  include('Class\Goods.php');
  $gid=$_GET["gid"];
  $obj = new Goods();
  $obj->Add_ClickTimes($gid);  // 增加点击次数
  $obj->GetGoodsInfo($gid);  // 获取商品信息
  include('Class\Users.php');
  //读取卖家信息
  $objUser = new Users();
  $objUser->GetUsersInfo($obj->OwnerId);
  //读取商品类型
  include('Class\GoodsType.php');
  $objType = new GoodsType();
  $objType->GetGoodsTypeInfo($obj->TypeId);
?>
<center><?PHP if($obj->ImageURL=="")
{
?><img src="images/noImg.jpg" height=50 border=0>
<?PHP }
  else
{
?><img src="user/images/<?PHP   echo($obj->ImageURL); ?>" height=250 border=0><br /><br />
<?PHP } ?></center>
<table align=center cellpadding=0 cellspacing=0 width=60% border=1 bordercolorlight="#4DA6FF" bordercolordark="#ECF5FF">
<tr><td align=center width=100% colspan=3 bgcolor=#eeeeee height=28><font color=#0000ff>
    商品信息</font></td></tr>
<tr><td align=right width=25% bgcolor=#eeeeee>商品名称:</td><td align=left><?PHP echo($obj->GoodsName); ?></td></tr>
<tr><td align=right bgcolor=#eeeeee>所 有 者:</td><td align=left><?PHP echo($objUser->Name); ?></td></tr>
<tr><td align=right bgcolor=#eeeeee>所属分类:</td><td align=left>
<?PHP echo($objType->TypeName); ?>
</td></tr>
<tr><td align=right bgcolor=#eeeeee>添加时间:</td><td align=left>
    <?PHP echo($obj->StartTime); ?></td></tr>
<tr><td align=right bgcolor=#eeeeee>商品价格:</td><td align=left><?PHP echo($obj->Price); ?></td></tr>
<tr><td align=right bgcolor=#eeeeee>新旧程度:</td><td align=left><?PHP echo($obj->OldNew); ?>&nbsp;</tr>
<tr><td align=right bgcolor=#eeeeee>保  修:</td><td align=left><?PHP echo($obj->Repaired); ?>&nbsp;</td></tr>
<tr><td align=right bgcolor=#eeeeee>发  票:</td><td align=left><?PHP echo($obj->Invoice); ?>&nbsp;</td></tr>
<tr><td align=right bgcolor=#eeeeee>运  费:</td><td align=left><?PHP echo($obj->Carriage); ?>&nbsp;</tr>
<tr><td align=right bgcolor=#eeeeee>支付方式:</td><td align=left><?PHP echo($obj->PayMode); ?>&nbsp;</td></tr>
<tr>
    <td align=right bgcolor=#eeeeee>送货方式:</td><td align=left><?PHP echo($obj->DeliverMode); ?>&nbsp;</td>
</tr>
<tr><td align=right bgcolor=#eeeeee>商品描述:</td>
<td align=left><textarea rows="2" name="adetail" cols="40"><?PHP echo($obj->GoodsDetail); ?></textarea></td></tr>
</table>
</form>
</center>
</body>
</html>
View Code

3.index.php          交易系统的主界面()

<html>
<head>
<?PHP session_start(); ?>
<link href=style.css rel=STYLESHEET type=text/css>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″> <title>二手交易市场</title></head>
<body>
<center>
<table border="0" width="760" cellspacing="0" cellpadding="0">
 <tr><td colspan="3" height="80"><img src="images/title.jpg" width="800" height="100" border="0"></td>
 </tr>
  <tr>
  <td colspan="2" bgcolor="#E1F5FF" height="19" valign="middle" align="left">
选择商品分类
<?PHP
  //从表GoodsType中读取商品类别数据
  include('Class\GoodsType.php');
  $gtype = new GoodsType();
  $results = $gtype->GetGoodsTypelist();
  //使用循环语句,依次显示分类信息
  while($row = $results->fetch_row())
  {  
?>
      <font color="#FF9933"">|</font>&nbsp;<a href="List.php?tid=<?PHP echo($row[0]); ?>" target="_blank"><?PHP echo($row[1]); ?></a>&nbsp;
<?PHP 
  } 
?>
  </td>  
  <td bgcolor="#E1F5FF" height="19" valign="middle" align="right">
  </td></tr>
<tr><td width="25%" valign="top" align="left"><?PHP include("left.php"); ?></td>
<td width="75%" valign="top" align="center">
<table border="1" width="100%" cellspacing="0" cellpadding="0" bordercolorlight="#63CFFF" bordercolordark="#FFFFFF">
<tr><td width="50%" bgcolor="#63CFFF" height="18">最新加入商品</td></tr>
<tr><td width="100%" valign="top" align="left" height="1">
<table border="1" width="100%"  cellspacing="1" bordercolorlight="#63CFFF" bordercolordark="#FFFFFF">
<tr>
<?PHP 
//  include('Class\Goods.php');
  $objGoods = new Goods();
  $results = $objGoods->GetTopnNewGoods(12);
  //如果没有找到商品,则显示提示信息
  $i=0;
  //否则使用循环语句,依次显示商品信息
  while($row = $results->fetch_row())
  {
?>        
    <td valign="top" width="33.33%" align="left" bgcolor="#FFFFFF">
    <p align="center">
<?PHP 
//显示商品图片
  if (!isset($row[5]) || trim($row[5])=="")
  {
?>
      <img border="0" src="images/noImg.jpg" height="110">
<?PHP 
  }
  else
  {
?>
      <a href="GoodsView.php?gid=<?PHP     echo($row[0]); ?>" target=_blank>
      <img border="0" src="user/images/<?PHP  echo($row[5]); ?>" width="100" height="110"></a>
<?PHP 
  } 
?>
</center>
    <br>商品名称:<a href="GoodsView.PHP?gid=<?PHP   echo($row[0]); ?>" target=_blank><?PHP    echo($row[3]); ?></a>
    <br>交易类型:
    <?PHP   if($row[2]==1)
  {
?>
       转让
    <?PHP   }
    else
    {
?>
       求购
    <?PHP   } ?>
    <br>所有者:<?PHP    echo($row[15]); ?>
    <br>价格:<?PHP   echo($row[6]); ?><br>发布时间:<?PHP   echo($row[7]); ?>
</td>
<center>
<?PHP 
  if ($i%3==2)
  {
?>
      </tr><tr>
<?PHP   } 

  $i++;
} 
  if ($i==0)
  {
?>
   <td width="100%" valign="top" align="left" bgcolor="#FFFFFF">暂且没有商品</td>
<?PHP 
} 
?>
</tr></table></center></table></td>    
  </tr>
</table>
</body>
</html>
View Code

4.left.php          用于显示主界面的左侧部分,包括站内公告、用户登录信息等信息

<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″> 
<title>首页</title>
<script language="javascript">
function BulletinWin(url) {
  var oth="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left=200,top=200";
  oth = oth+",width=400,height=300";
  var BulletinWin = window.open(url,"BulletinWin",oth);
  BulletinWin.focus();
  return false;
}
</script>
</head>
<body>
<table border="1" width="100%" cellspacing="0" cellpadding="0" bordercolorlight="#FF9933" bordercolordark="#FFFFFF" bgcolor="#FFFFFF">
      <tr>         
          <td width="100%" height="24" bgcolor="#63CFFF" align="center">
            <font color="#FF0000"><b>站内公告</b></font></td>  
      </tr>         
<?PHP 
  //session_start();
  include('Class\Bulletin.php');
  $obj = new Bulletin();
  $results = $obj->GetBulletinlist();
  //显示新闻信息     
?>
        <tr>         
          <td width="100%" bgcolor="#E1F5FF" height="70" valign="top">      
<?PHP 
  $exist = false;
  //按时间显示最新的10条新闻信息
  for ($i=1; $i<=10; $i++)
  {
    $exist = true;
    if($row = $results->fetch_row())
    {
      $title=$row[1];
      //显示新闻标题以及网页链接
      if(strlen($title)>29)//设置公告标题显示长度
      {
        $title=substr($title,0,29);
?><a href="BulletinView.php?id=<?PHP       echo($row[0]); ?>" onClick="return BulletinWin(this.href)";target=_blank><?PHP       echo $title; ?>......</a>         
         <?PHP     }
      else
    {
?>            
         <a href="BulletinView.php?id=<?PHP       echo($row[0]); ?>" onClick="return BulletinWin(this.href)";target=_blank><?PHP       echo($title); ?></a> 
         <?PHP     } // end of else ?><br> 
         <?PHP   }  //else of if  ?>
    <?PHP   }   // else of for  ?>         
          </td>         
        </tr>
    <?PHP   
       if(!$exist)
       {
?>         
      <tr>         
          <td width="100%" height="70" bgcolor="#E1F5FF">暂且没有公告 </td>     
      </tr>             
<?PHP }
  include('Class\Users.php');
  //从Session变量中读取注册用户信息,并连接到数据库验证
  $objUser = new Users();
  @$UserId=trim($_SESSION["user_id"]);
  @$Pwd=trim($_SESSION["user_pwd"]);
  //连接数据库,进行身份验证
  $objUser->GetUsersInfo($UserId);
  $_SESSION["user_name"]=$objUser->Name;
  if($UserId!="" && $objUser->UserPwd==$Pwd)
  {
?>
       <tr>
       <td width="100%" bgcolor="#97DDFF" height="18" align="center">用户信息</td>
        </tr>
        <tr>
          <td width="100%" height="18" bgcolor="#E1F5FF">
            <table border="0" cellspacing="1" width="100%">
              <tr>
                <td width="100%" bgcolor="#E1F5FF">用户名:<?PHP echo($objUser->UserId); ?><br>地址:                         
                <?PHP   echo($objUser->Address); ?><br>         
                E-mail:<?PHP   echo($objUser->Email); ?><Br>电话:<?PHP   echo($objUser->Telephone); ?>
                </td>         
              </tr> 
              <tr>
                <td width="100%" align="center" bgcolor="#E1F5FF">
                <a href='user\UserView.php?uid=<?PHP   echo($objUser->UserId); ?>' target="_blank">我的商品</a>
                &nbsp;<a href="LoginExit.php" onclick="return newswin(this.href)">退出登录</a>
        &nbsp;<a href='user\PwdChange.php?uid=<?PHP   echo($objUser->UserId); ?>' >修改密码</a>
                </td>         
              </tr>     
            </table>         
          </td>         
        </tr> 
     <?PHP }
  else
{
?>
        <tr>         
          <td width="100%" bgcolor="#97DDFF" height="24" align="center">用户登录</td>
        </tr>         
        <tr>         
          <td width="100%" height="18" bgcolor="#E1F5FF">         
            <table border="0" cellspacing="1" height="58">         
              <tr>         
                <td width="100%" bgcolor="#E1F5FF" height="35">         
                  <form method="POST" action="putSession.php">         
                    用户名: 
                    <input type="text" name="loginname" size="18" value="">         
                    <br>密&nbsp;码: 
                    <input type="password" name="password" size="18" value="">                            
                    <br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="确定" name="B1">
                    &nbsp;&nbsp;
                    <a href="user/UserAdd.php"  target=_blank>用户注册</a>                           
                  </form>         
                </td>         
              </tr>         
            </table>         
          </td>         
        </tr>         
      <?PHP } ?>  
      </table>
       <table border="1" width="100%" cellspacing="0" cellpadding="0" bordercolorlight="#FF9933" bordercolordark="#FFFFFF" bgcolor="#FFFFFF">
   <tr>
     <td bgcolor="#97DDFF" height="24" align="center">最被关注商品 TOP 
       10</td>
   </tr>
   <tr>
     <td bgcolor="#E1F5FF"><table border="0" width="100%" cellspacing="0"  bordercolorlight="#FF9933" bordercolordark="#FFFFFF">
         <tr>
           <td width="100%" height="37" bgcolor="#E1F5FF">
<?PHP 
  include('Class\Goods.php');
  $objGoods = new Goods();
  //查询前10个点击次数(ClickTimes)最多的\未结束的商品信息
  $results = $objGoods->GetTopnMaxClick(10);
  $exist = false;
  //如果结果集为空,则显示提示信息

//依次显示结果集中的商品信息
  while($row = $results->fetch_row())
  {
    $exist = true;
?>
               <a href="GoodsView.php?gid=<?PHP     echo($row[0]); ?>" target="_blank"><?PHP     echo($row[3]); ?></a> (浏览<font color="red"><?PHP     echo($row[16]); ?></font>次)<br />
               <?PHP 
  } 
  if (!$exist)
  {
    print "暂且没有商品";
  }
?></td>
         </tr>
     </table></td>
   </tr>
      <tr>
        <td width="100%" bgcolor="#97DDFF" height="24" align="center">最新活跃卖家 TOP 10</td>
      </tr>
      <tr>
        <td width="100%" valign=top height="52" bgcolor="#E1F5FF">
          <table border="0" cellspacing="0" bordercolorlight="#FF9933" bordercolordark="#FFFFFF" bgcolor="#FFFFFF">
            <tr>
              <td width="100%" bgcolor="#E1F5FF">
<?PHP 
  //获取发布商品最多的用户
  $objUser = new Users();
  $results = $objUser->GetTopnActiveUser(10);
  $exist = false;
  //使用循环语句,依次显示分类信息
  while($row = $results->fetch_row())
  {
    $exist = true;
?>
      <a href="user\UserView.php?uid=<?PHP echo($row[0]); ?>" target=_blank><?PHP     echo($row[1]); ?></a>(<font color=red>
      <?PHP echo($row[2]); ?>
</font>件)<br>
<?PHP 
  } 
  //如果结果集为空,则显示提示信息
  if(!$exist)
  {
    print "暂且没有用户信息";
  }
?>              </td>
            </tr>
          </table>        </td>
      </tr>
 </table>

      </body>
</html>
View Code

5.list.php           分类查看商品信息。在这个界面用户还可以执行 转让 和 求购功能

<html>
<head>
<link href=style.css rel=STYLESHEET type=text/css>
<script language="javascript">
function newwin(url) {
  var oth="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left=200,top=100";
  oth = oth+",width=600,height=500";
  var newwin = window.open(url,"newwin",oth);
  newwin.focus();
  return false;
}
</script>
</head>
<body>
<center>
<table border="0" width="760" cellspacing="0" cellpadding="0">
 <tr><td height="80"><a href="images/title.jpg">
    <img src="images/title.jpg" border="0" width="800" height="100"></a></td></tr>
  <tr>
  <td bgcolor="#E1F5FF" height="19" valign="middle" align="left">
<?PHP 
  //读取参数, tid表示商品类型编号,flag表示转让或求购类型
  $tid=intval($_GET["tid"]);
  @$flag=intval($_GET["flag"]);
  if($flag==0)
  {
?>
   <B>转让信息</B>&nbsp;&nbsp;<a href="list.php?flag=1&tid=<?PHP echo($tid); ?>">求购信息</a>
  <?PHP }
  else
{
?>
   <a href="list.php?flag=0&tid=<?PHP   echo($tid); ?>">转让信息</a>&nbsp;&nbsp;<B>求购信息</B>
  <?PHP } ?>   
  </td>  
  </tr>
<tr><td width="16%" valign="top" align="left"  bgcolor="#E1F5FF">
<table border="1" width="100%" cellspacing="1" bordercolorlight="#63CFFF" bordercolordark="#FFFFFF"  bgcolor="#E1F5FF">
<tr>
<td valign="top" colspan=2 align="center">
<table border=1 width=100% cellspacing=0 bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF">
<tr><td colspan=6 bgcolor="#FFFFFF">
    <p align="center"><font color=#3399FF><b>【商品信息 - 
<?PHP 
  include('Class\GoodsType.php');
  $objType = new GoodsType();
  $objType->GetGoodsTypeInfo($tid);
  echo($objType->TypeName);
?>】</b></font></td></tr>
<tr><td colspan=6 bgcolor="#FFFFFF">
<center><input type="button" value="我要转让" onclick="newwin('user/GoodsAdd.php?flag=0&tid=<?PHP echo($tid); ?>')" name=add>&nbsp;&nbsp;
<input type="button" value="我要求购" onclick="newwin('user/GoodsAdd.php?flag=1&tid=<?PHP echo($tid); ?>')" name=add></center></td></tr>

<tr>
<td align=center width="15%" bgcolor="#E1F5FF">商品图片</td>
<td align=center width="20%" bgcolor="#E1F5FF">商品名称</td>
<td align=center width="15%" bgcolor="#E1F5FF">价格</td>
<td align=center width="12%" bgcolor="#E1F5FF">新旧程度</td>
<td align=center width="12%" bgcolor="#E1F5FF">卖家</td>
<td align=center width="26%" bgcolor="#E1F5FF">发布时间</td>
</tr>
<?PHP 
  //设置转让或求购的查询条件
  if($flag==0)
  {
    $cond=" WHERE SaleOrBuy=1";
  }
  else
  {
    $cond=" WHERE SaleOrBuy=2";
  } 

  //设置商品分类查询条件
  if ($tid>0)
  {
    $cond=$cond." AND TypeId=".$tid;
  } 
  // 只查看未结束的商品
  $cond=$cond." AND IsOver=0";
  //创建Goods对象,读取满足条件的记录
  include('Class\Goods.php');
  $obj = new Goods();
  $results = $obj->GetGoodslist($cond);
  $m=0;
  while($row = $results->fetch_row())
  {
?>
  <tr><td align=center bgcolor="#FFFFFF"><?PHP   if ($row[5]=="")
  {
?><img src="images/noImg.jpg" height=50 border=0>
<?PHP   }
    else
  {
?><img src="user/images/<?PHP     echo($row[5]); ?>" height=50 border=0>
<?PHP   } ?></td>
  <td align=center bgcolor="#FFFFFF"><a href="GoodsView.php?gid=<?PHP echo($row[0]); ?>" target=_blank><?PHP   echo($row[3]); ?></a></td>
  <td align=center bgcolor="#FFFFFF"><?PHP   echo($row[6]); ?></td>
  <td align=center bgcolor="#FFFFFF"><?PHP   echo($row[8]); ?>&nbsp;</td>
  <td align=center bgcolor="#FFFFFF"><a href="user/UserView.php?uid=<?PHP echo($row[15]); ?>" target=_blank><?PHP   echo($row[15]); ?></a></td>
  <td bgcolor="#FFFFFF" align="center"><?PHP   echo($row[7]); ?></td>
  </tr>  
<?PHP   $m=$m+1;
  } 
  if ($m==0)
  {
    print "<tr><td bgcolor=#FFFFFF align=center colspan=6>暂无商品信息</td></tr>";
  }  
?>
</table>
</td>
</tr>
</table>
</body>
</html>
View Code

6.LoginExit.php      处理用户退出系统操作

<?PHP
  session_start();
  $_SESSION["user_id"]="";
  $_SESSION["user_pwd"]="";
  header("Location: "."index.php");
?>
View Code

7.putSession.php     处理用户登录操作(将用户名和密码提交给 服务器)

<?PHP
  session_start();
  //取输入的用户名和密码
  $UID=$_POST["loginname"];
  $PSWD=$_POST["password"];

  // 把用户名和密码放入session
  $_SESSION["user_id"]=$UID;
  $_SESSION["user_pwd"]=$PSWD;
  header("Location: index.php");
?>
View Code

 


 

 Class文件包含3个文件 Bullentin.php(Bullentin类) 、 Goods.php(Goods类) 和 GoodsType.php(GoodsType类)以及Users.php(Users类)

Bullentin.php    本类用于保存对表Bulletin的数据库访问操作

<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″> 
<?PHP
//本类用于保存对表Bulletin的数据库访问操作
//表的每个字段对应类的一个成员变量
Class Bulletin
{
  public $Id;                // 记录编号
  public $Title;            // 公告标题
  public $Content;            // 公告内容
  public $PostTime;            // 发布日期
  public $Poster;            // 发布人
  var $conn;

  function __construct() {
    // 连接数据库
    $this->conn = mysqli_connect("localhost", "root", "123456", "2shou"); 
    mysqli_query($this->conn, "SET NAMES utf-8");
  }
        
  function __destruct() {
    // 关闭连接
    mysqli_close($this->conn);
  }

  // 获取公告信息
  function GetBulletinInfo($bid)  {
    //设置查询的SELECT语句
     $sql = "SELECT * FROM Bulletin WHERE Id='" . $bid . "'";
    // 打开记录集
    $results = $this->conn->query($sql);
    // 读取公告数据
    if($row = $results->fetch_row())  {
        $this->Id = $bid;
      $this->Title = $row[1];
      $this->Content = $row[2];
      $this->PostTime = $row[3];
      $this->Poster = $row[4];
    }
    else {
      $this->Id=0;
    }
  }

  // 获取所有公告信息,返回结果集
  function GetBulletinlist()  {
    //设置查询的SELECT语句
    $sql = "SELECT * FROM Bulletin ORDER BY PostTime DESC";
    $results = $this->conn->query($sql);
    return $results;
  }

  // 获取所有公告信息,返回结果集
  function GetRecentBulletinlist()  {
    //设置查询的SELECT语句
    $sql = "SELECT * FROM Bulletin WHERE DateDiff(day, getdate(), Posttime)<=7";
    $results = $this->conn->query($sql);
    return $results;
  }

  // 添加公告信息
  function insert()  {
    $sql = "INSERT INTO Bulletin (Title, Content, PostTime, Poster) VALUES ('" . $this->Title . "','" . $this->Content . "','" . $this->PostTime . "','" . $this->Poster . "')";
    // 执行SQL语句
    $this->conn->query($sql);
  }

  // 修改公告信息
  function update($bid)  {
    $sql = "UPDATE Bulletin SET Title='" . $this->Title . "', Content='" . $this->Content . "', PostTime='" . $this->PostTime . "', Poster='" . $this->Poster . "' WHERE Id=" . $bid;
    // 执行SQL语句
    $this->conn->query($sql);
  }

  // 批量删除公告信息
  function delete($bid)  {
    $sql = "DELETE FROM Bulletin WHERE Id IN (" . $bid . ")";
    // 执行SQL语句
    $this->conn->query($sql);
  }
}
?>
View Code

 Goods.php      本类用于保存对表Goods的数据库访问操作

<?PHP
//本类用于保存对表Goods的数据库访问操作
//表的每个字段对应类的一个成员变量
class Goods  {
  public $GoodsId;                // 记录编号
  public $GoodsName;            // 商品名称
  public $TypeId;                // 类型编号
  public $SaleOrBuy;            // 交易类型,1表示转让,2表示求购
  public $GoodsDetail;            // 商品说明
  public $ImageURL;                //  图片链接地址
  public $Price;                //  转让价格
  public $StartTime;            // 开始时间
  public $OldNew;                // 新旧程度
  public $Invoice;                // 是否有发票
  public $Repaired;                // 是否保修
  public $Carriage;                // 运费
  public $PayMode;                // 支付方式
  public $DeliverMode;            // 送货方式
  public $IsOver;                // 是否结束
  public $OwnerId;                // 卖家用户名
  public $ClickTimes;            // 点击次数
  var $conn;

  function __construct() {
    // 连接数据库
    $this->conn = mysqli_connect("localhost", "root", "123456", "2shou"); 
    mysqli_query($this->conn, "SET NAMES utf-8");
  }
        
  function __destruct() {
    // 关闭连接
    mysqli_close($this->conn);
  }

  // 获取商品信息
  function GetGoodsInfo($id)  {
    // 设置查询的SELECT语句
     $sql = "SELECT * FROM Goods WHERE GoodsId=" . $id;
    //打开记录集
    $results = $this->conn->query($sql);
    // 读取个人数据
    if($row = $results->fetch_row()) {
      $this->GoodsId = $id;
      $this->TypeId = $row[1];
      $this->SaleOrBuy = $row[2];
      $this->GoodsName = $row[3];
      $this->GoodsDetail = $row[4];
      $this->ImageURL = $row[5];
      $this->Price = $row[6];
      $this->StartTime = $row[7];
      $this->OldNew = $row[8];
      $this->Invoice = $row[9];
      $this->Repaired = $row[10];
      $this->Carriage = $row[11];
      $this->PayMode = $row[12];
      $this->DeliverMode = $row[13];
      $this->IsOver = $row[14];
      $this->OwnerId = $row[15];
      $this->ClickTimes = $row[16];
    }
    else  {
      $GoodsId=0;
    }
  }

  // 根据查询条件获取所有商品信息,返回结果集
  function GetGoodslist($cond)  {
    // 设置查询的SELECT语句
    $sql = "SELECT * FROM Goods" . $cond . " ORDER BY StartTime DESC";
    //打开记录集
    $results = $this->conn->query($sql);
    return $results;
  }

  // 获取前n名最新添加的商品
  function GetTopnNewGoods($n)  {
    // 设置查询的SELECT语句
    $sql = "SELECT * FROM Goods WHERE IsOver=0 ORDER BY StartTime DESC LIMIT 0," . $n;
    //打开记录集
    $results = $this->conn->query($sql);
    return $results;
  }

  // 获取前n名最受关注的商品
  function GetTopnMaxClick($n)  {
    // 设置查询的SELECT语句
    $sql = "SELECT * FROM Goods WHERE IsOver=0 ORDER BY ClickTimes DESC, StartTime DESC LIMIT 0," . $n;
    //打开记录集
    $results = $this->conn->query($sql);
    return $results;
  }

  // 判断指定商品分类是否存在
  function HaveGoodsType($tid)  {
    //设置查询的SELECT语句
    $sql = "SELECT * FROM Goods WHERE TypeId=" . $tid;
    //打开记录集
    $results = $this->conn->query($sql);
    if($row = $results->fetch_row()) 
        $exist = true;
    else
      $exist = false;
    return $exist;
  }

  // 添加信息
  function insert()  {
    $sql = "INSERT INTO Goods (TypeId, SaleOrBuy, GoodsName, GoodsDetail, ImageUrl, Price, StartTime, OldNew, Invoice, Repaired, Carriage, PayMode, DeliverMode, IsOver, OwnerId, ClickTimes) VALUES (" . $this->TypeId. "," . $this->SaleOrBuy . ",'" . $this->GoodsName . "','" . $this->GoodsDetail . "','" . $this->ImageUrl . "','" . $this->Price . "','" . $this->StartTime . "','" . $this->OldNew . "','" . $this->Invoice . "','" . $this->Repaired . "','" . $this->Carriage . "','" . $this->PayMode . "','" . $this->DeliverMode . "',0,'" . $this->OwnerId . "',0)";
    //执行SQL语句
    $this->conn->query($sql);
  }

  function update($id)  {
    $sql = "UPDATE Goods SET GoodsName='" . $this->GoodsName . "', TypeId=" . $this->TypeId . ", GoodsDetail='" . $this->GoodsDetail . "', Price='" . $this->Price . "', OldNew='" . $this->OldNew . "', Invoice='" . $this->Invoice . "', Repaired='" . $this->Repaired . "', Carriage='" . $this->Carriage . "', PayMode='" . $this->PayMode . "', DeliverMode='" . $this->DeliverMode . "' WHERE GoodsId=" . $id;
    //执行SQL语句
    $this->conn->query($sql);
  }

  function Add_ClickTimes($id)  {
    $sql = "UPDATE Goods SET ClickTimes=ClickTimes+1 WHERE GoodsId=" . $id;
    $this->conn->query($sql);
  }
  
  function SetOver($id)  {
    $sql = "UPDATE Goods SET IsOver=1 WHERE GoodsId=" . $id;
    $this->conn->query($sql);
  }

  // 批量删除信息
  function delete($id) {
    $sql = "DELETE FROM Goods WHERE GoodsId IN (" . $id . ")";
    $this->conn->query($sql);
  }
}
?>
View Code

 GoodsType.php    本类用于保存对表GoodsType的数据库访问操作

<?PHP
//本类用于保存对表GoodsType的数据库访问操作
//表的每个字段对应类的一个成员变量
class GoodsType
{
  public $TypeId; // 照片类型编号
  public $TypeName; // 照片类型名称
  var $conn;

  function __construct() {
    // 连接数据库
    $this->conn = mysqli_connect("localhost", "root", "123456", "2shou"); 
    mysqli_query($this->conn, "SET NAMES utf-8");
  }
        
  function __destruct() {
    // 关闭连接
    mysqli_close($this->conn);
  }

  //获取分类信息
  function GetGoodsTypeInfo($id)
  {
    //设置查询的SELECT语句
    $sql="SELECT * FROM GoodsType WHERE TypeId=".$id;
    //打开记录集
    $results = $this->conn->query($sql);
    //读取分类数据
    if($row = $results->fetch_row())
    {
      $this->TypeId=$id;
      $this->TypeName=$row[1];
    } 
    else
    {
      $TypeId="";
    }
  }

  //获取所有分类信息,返回结果集
  function GetGoodsTypelist()
  {
    //设置查询的SELECT语句
    $sql="SELECT * FROM GoodsType";
    //打开记录集
    $results = $this->conn->query($sql);
    return $results;
  } 

  // 判断指定商品分类是否存在
  function HaveGoodsType($name)
  {
    //设置查询的SELECT语句
    $sql="SELECT * FROM GoodsType WHERE TypeName='" . $name . "'";
    //打开记录集
    $results = $this->conn->query($sql);
    if($row = $results->fetch_row()) 
        $exist = true;
    else
      $exist = false;
    return $exist;
  } 

  //添加分类信息
  function insert()
  {
    $sql="INSERT INTO GoodsType (TypeName) VALUES ('".$this->TypeName."')"; 
    //执行SQL语句
    $results = $this->conn->query($sql);
  } 

  //修改分类信息
  function update($id)
  {
    $sql="UPDATE GoodsType SET TypeName='".$this->TypeName."' WHERE TypeId="
    .$id;
    //执行SQL语句
    $results = $this->conn->query($sql);
  } 

  //删除分类信息
  function delete($id)
  {
    $sql="DELETE FROM GoodsType WHERE TypeId IN (".$id.")";
    //执行SQL语句
    $results = $this->conn->query($sql);
  } 
}
?>
View Code

 Users.php       本类用于保存对表Users的数据库访问操作

<?PHP
//本类用于保存对表Users的数据库访问操作
//表的每个字段对应类的一个成员变量
class Users  
{
    public $UserId;        // 用户名
    public $UserPwd;    // 密码
    public $Name;        // 姓名
    public $Sex;        // 性别
    public $Address;    // 地址
    public $Postcode;   // 邮编
    public $Email;        // 电子邮件
    public $Telephone;    // 电话
    public $Mobile;        // 手机
    public $UserType;    // 用户类型
    var $conn;

  function __construct() {
    // 连接数据库
    $this->conn = mysqli_connect("localhost", "root", "123456", "2shou"); 
    mysqli_query($this->conn, "SET NAMES utf-8");
  }
        
  function __destruct() {
    // 关闭连接
    mysqli_close($this->conn);
  }


  //获取个人信息
  function GetUsersInfo($uid)
  {
    $sql="SELECT * FROM Users WHERE UserId='".$uid."'";
    $results = $this->conn->query($sql);
    if($row = $results->fetch_row())  {
      $this->UserId=$uid;
      $this->UserPwd=$row[1];
      $this->Name=$row[2];
      $this->Sex=$row[3];
      $this->Address=$row[4];
      $this->Postcode=$row[5];
      $this->Email=$row[6];
      $this->Telephone=$row[7];
      $this->Mobile=$row[8];
      $this->UserType=$row[9];
    }
    else
      $this->UserId = "";
  } 

  //获取所有个人信息,返回结果集
  function GetUserslist()
  {
    //设置查询的SELECT语句
    $sql="SELECT * FROM Users";
    //打开记录集
    $results = $this->conn->query($sql);
    return $results;
  } 

  function GetTopnActiveUser($n)
  {
    //设置查询的SELECT语句
    $sql="SELECT u.UserId, u.Name, Count(g.GoodsId) AS cc "
    ." FROM Users u INNER JOIN Goods g ON u.UserId=g.OwnerId "
    ." GROUP BY u.UserId, u.Name "
    ." ORDER BY Count(g.GoodsId) DESC LIMIT 0," . $n;
    //打开记录集
    $results = $this->conn->query($sql);
    return $results;
  } 

  // 判断指定用户名是否存在
  function HaveUsers($uid)
  {
    //设置查询的SELECT语句
    $sql="SELECT * FROM Users WHERE UserId='".$uid."'";
    //打开记录集
    $results = $this->conn->query($sql);
    if($row = $results->fetch_row()) 
      $exist=true;
    else
      $exist=false;
    return $exist;
  } 

  // 判断指定用户名和密码是否存在
  function CheckUser()
  {
    //设置查询的SELECT语句
    $sql="SELECT * FROM Users WHERE UserId='".$this->UserId."' AND UserPwd='".$this->UserPwd."'";
    //打开记录集
    $results = $this->conn->query($sql);
    if($row = $results->fetch_row()) 
      $exist=true;
    else
      $exist=false;
    return $exist;
  } 

  //添加个人信息
  function insert()
  {
    $sql="INSERT INTO Users VALUES ('" . $this->UserId . "','" . $this->UserPwd
     . "','" . $this->Name . "'," . $this->Sex . ",'" . $this->Address . "','" . $this->Postcode . "','" . $this->Email . "','" . $this->Telephone . "','" . $this->Mobile . "'," . $this->UserType . ")";
    //执行SQL语句
    $this->conn->query($sql);
  } 

  //修改个人信息
  function update($uid)
  {
    $sql="UPDATE Users SET Name='" . $this->Name . "', Sex=" . $this->Sex . ", Address='" . $this->Address . "', Postcode='" . $this->Postcode . "', Email='" . $this->Email . "', Telephone='" . $this->Telephone . "', Mobile='" . $this->Mobile . "' WHERE UserId='" . $uid . "'";
    //执行SQL语句
    $this->conn->query($sql);
  } 

  function setpwd($uid)
  {
    $sql="UPDATE Users SET UserPwd='" . $this->UserPwd . "' WHERE UserId='" . $uid . "'";
    $this->conn->query($sql);
  } 

  //删除个人信息
  function delete($uid)
  {
    $sql="DELETE FROM Users WHERE UserId='".$uid."'";
    $this->conn->query($sql);
  } 
}
?>
View Code

 


 

 1.AdminPwdChange.php    修改管理员密码(后台)

<?PHP include('isAdmin.php'); ?>
<link href="../style.css" rel="stylesheet">
<?PHP
  session_start();
  $uid=$_SESSION["UserName"];
?>
<html>
<head>
<title>修改密码</title>
</head>
<Script Language="JavaScript">
function ChkFields() {
  if (document.myform.OriPwd.value=='') {
    alert("请输入原始密码!")
    return false
  }
  if (document.myform.Pwd.value.length<6) {        
    alert("新密码长度大于等于6!")
    return false
  }
  if (document.myform.Pwd.value!=document.myform.Pwd1.value) {        
    alert("两次输入的新密码必须相同!")
    return false
  }
  return true
}
</Script>
<body>
<form method="POST" action="AdminSavePwd.php?aid=<?PHP echo($uid); ?>" name="myform" onsubmit="return ChkFields()">
<p align="center">修改密码</p>
<table align="center" border="1" cellpadding="1" cellspacing="1" width="263" bordercolor="#008000" bordercolordark="#FFFFFF" height="134">
      <tr>
        <td align=left width="86" height="18">用户名</td>
        <td width="161" height="18"><?PHP echo($uid); ?></td>
      </tr>
      <tr>
        <td align=left width="86" height="23">原始密码</td>
        <td width="161" height="23"><input type="password" name="OriPwd"></td>
      </tr>
      <tr>
        <td align=left width="86" height="23">新密码</td>
        <td width="161" height="23"><input type="password" name="Pwd"></td>
      </tr>
      <tr>
        <td align=left width="86" height="23">密码确认</td>
        <td width="161" height="23"><input type="password" name="Pwd1"></td>
      </tr>
  </table> 
<p align="center">
<input type="submit" value=" 提 交 " name="B2"></p>
</form>  
</body>
</html>
View Code

2.AdminSavePwd.php      保存管理员修改的密码(修改后密码来自1.AdminPwdChange.php)

<?PHP include('isAdmin.php'); ?>
<html>
<head>
<title>修改管理员密码</title>
</head>
<body>
<?PHP 
  //session_start();
  $OriPwd=$_POST["OriPwd"];
  $Pwd=$_POST["Pwd"];
  //判断是否存在此用户
  include('..\Class\Users.php');
  $obj = new Users();
  $obj->UserId=$_SESSION["UserName"];
  $obj->UserPwd=$OriPwd;
  if($obj->CheckUser()==false)
  {
    print("不存在此用户名或密码错误!");
?>
    <Script Language="JavaScript">    
      setTimeout("history.go(-1)",1600);            
      </Script>
<?PHP 
  }
  else
  {
    $obj->UserPwd=$Pwd;
    $obj->setpwd($obj->UserId);
    print("<h2>更改密码成功!</h2>");
    $_SESSION["UserPwd"]=trim($Pwd);
  } 
?>    
</body>
</html>
View Code

3.BulletinAdd.php        添加公告页面

<?PHP include('isAdmin.php'); ?>
<html>
<head>
<title>二手交易市场公告</title>
<link href=../style.css rel=STYLESHEET type=text/css>
<script language="javascript">
  function checkFields()
  {
    if (myform.title.value=="") {
       alert("公告题目不能为空");
       myform.title.onfocus();
       return false;
    }
    if (myform.content.value=="") {
       alert("公告内容不能为空");
       myform.content.onfocus();
       return false;
    }
    return true;
  }
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"><style type="text/css">
<!--
body {
    background-color: #FFFFFF;
}
-->
</style></head>
<body>
<form name="myform" method="POST" action="BulletinSave.php?action=add" OnSubmit="return checkFields()">
        <table border="0" width="100%" cellspacing="1">
          <tr>
            <td width="100%">公告标题
            <input type="text" name="title" size="20"></td>
          </tr>
          <tr>
            <td width="100%">公告内容</td>
          </tr>
          <tr>
            <td width="100%"><textarea rows="12" name="content" cols="55"></textarea></td>
          </tr>
        </table>
        <p align="center"><input type="submit" value=" 提 交 " name="B1">
        <input type="reset" value=" 重写 " name="B2"></p>
</form>
</body>
</html>
View Code

4.BulletinDelt.php        删除公告处理操作

<?PHP include('isAdmin.php'); ?>
<html>
<head>
<link href=../style.css rel=STYLESHEET type=text/css>
</head>
<body>
<?PHP 
  //从数据库中批量删除公告信息
  //读取要删除的公告编号
  $id=$_GET["id"];
  include('..\Class\Bulletin.php');
  $obj = new Bulletin();
  $obj->delete($id);
?>
</form>
</body>
<script language="javascript">
  alert("成功删除!");
  location.href = "BulletinList.php";
</script>
</html>
View Code

5.BulletinEdit.php        修改公告页面

<?PHP include('isAdmin.php'); ?>
<html>
<head>
<title>编辑公告信息</title>
<link href=../style.css rel=STYLESHEET type=text/css>
<script language="javascript">
  function checkFields()
  {
    if (myform.title.value=="") {
       alert("公告题目不能为空");
       myform.title.onfocus();
       return false;
    }
    if (myform.content.value=="") {
       alert("公告内容不能为空");
       myform.content.onfocus();
       return false;
    }
    return true;
  }
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"><style type="text/css">
<!--
body,td,th {
    color: #D4D0C8;
}
body {
    background-color: #FFFFFF;
}
.STYLE1 {color: #000000}
-->
</style></head>
<body>

<?PHP
  //从数据库中取得此公告信息
  //读取参数id
  $id=$_GET["id"];
  //根据参数id读取指定的公告信息
  include('..\Class\Bulletin.php');
  $obj = new Bulletin();
  $obj->GetBulletinInfo($id);
  //如果记录集为空,则显示没有此公告
  echo ($id);
  if($obj->Id==0)
  {
    exit("没有此公告");
  }
  else
  {
      
  //下面内容是在表格中显示公告内容
?>
<form name="myform" method="POST" action="BulletinSave.php?action=update&id=<?PHP   echo($id); ?>" OnSubmit="return checkFields()">
        <table border="0" width="100%" cellspacing="1">
          <tr>
            <td width="100%" bgcolor="#FFFFFF"><span class="STYLE1">公告标题
            <input type="text" name="title" size="20" value="<?PHP   echo($obj->Title); ?>">
            </span></td>
          </tr>
          <tr>
            <td width="100%" bgcolor="#FFFFFF"><span class="STYLE1">公告内容</span></td>
          </tr>
          <tr>
            <td width="100%" bgcolor="#FFFFFF"><textarea rows="12" name="content" cols="55"><?PHP echo($obj->Content); ?></textarea></td>
          </tr>
  </table>
        <p align="center"><input type="submit" value=" 提 交 " name="B1">
        <input type="reset" value=" 重写 " name="B2"></p>
<?PHP 
} 
?>
</form>
</body>

</html>
View Code

6.BulletinList.php        公告管理页面(可删除,修改,添加等)

<?PHP include('isAdmin.php'); ?>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>公告管理</title>
<link href="../style.css" rel="stylesheet">
<script language="javascript">
function BulletinWin(url) {
  var oth="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left=200,top=200";
  oth = oth+",width=400,height=300";
  var BulletinWin = window.open(url,"BulletinWin",oth);
  BulletinWin.focus();
  return false;
}

function SelectChk()  //删除
{
  var s = false; //用来记录是否存在被选中的复选框
  var Bulletinid, n=0; 
  var strid, strurl;
  var nn = self.document.all.item("Bulletin"); //返回复选框Bulletin的数量
  for (j=0; j<nn.length; j++) {
   // if (self.document.all.item("Bulletin",j).checked) {
    if (nn[j].checked) {
      n = n + 1;
      s = true;
      //Bulletinid = self.document.all.item("Bulletin",j).id+"";  //转换为字符串
      Bulletinid = nn[j].id+"";  //转换为字符串
      //生成要删除公告编号的列表
      if(n==1) {
        strid = Bulletinid;
      }
      else {
        strid = strid + "," + Bulletinid;
      }
    }
  }
  strurl = "BulletinDelt.php?id=" + strid;
  if(!s) {
    alert("请选择要删除的公告!");
    return false;
  }    
  if (confirm("你确定要删除这些公告吗?")) {
    form1.action = strurl;
    form1.submit();
  }
}

function sltAll() //全选
{
    var nn = self.document.all.item("Bulletin");
    for(j=0;j<nn.length;j++)
    {
        //self.document.all.item("Bulletin",j).checked = true;
    nn[j].checked = true;
    }
}
function sltNull()  //清空
{
    var nn = self.document.all.item("Bulletin");
    for(j=0;j<nn.length;j++)
    {
        nn[j].checked = false;
    }
}
</script>
</head>
<body link="#000080" vlink="#080080">
<form name="form1" method="POST">
<?PHP
  include('..\Class\Bulletin.php');
  //查询表Bulletin中的公告信息
  $obj = new Bulletin();
  $results = $obj->GetBulletinlist();
  $exist = false;
?>
<p align=center><font style='FONT-SIZE:12pt' color="#000080"><b>公 告 管 理</b></font></p>
<table align=center border="1" cellspacing="0" width="100%" bordercolorlight="#4DA6FF" bordercolordark="#ECF5FF" style='FONT-SIZE: 9pt'>
  <tr>
   <td width="50%" align="center" bgcolor="#eeeeee"><strong>题目</strong></td>
   <td width="30%" align="center" bgcolor="#eeeeee"><strong>时间</strong></td>
   <td width="10%" align="center"  bgcolor="#eeeeee"><strong>修改</strong></td>
   <td width="10%" align="center"  bgcolor="#eeeeee"><strong>选择</strong></td>
  </tr>
<?PHP 
  //依次显示公告信息
  while($row = $results->fetch_row())
  {
    $exist = true;
?>
  <tr>
    <td><a href="../BulletinView.php?id=<?PHP echo($row[0]); ?>" onClick="return BulletinWin(this.href)"><?PHP echo($row[1]); ?></a></td>
    <td align="center"><?PHP echo($row[3]); ?></td>
    <td align="center"><a href="BulletinEdit.php?id=<?PHP echo($row[0]); ?>" onClick="return BulletinWin(this.href)">修改</a></td>
    <td align="center"><input type="checkbox" name="Bulletin" id="<?PHP echo($row[0]); ?>" style="font-size: 9pt"></td>
  </tr>
<?PHP 
  } 
  if (!$exist)
  {
    print "<tr><td colspan=5 align=center>目前还没有公告。</td></tr></table>";
  }
?>
</table>
    <p align="center">
        <input type="button" value="添加公告" onclick="BulletinWin('BulletinAdd.php')" name=add>
         &nbsp;&nbsp;<input type="button" value="全 选" onclick="sltAll()" name=button1>
         &nbsp;&nbsp;<input type="button" value="清 空" onclick="sltNull()" name=button2>
          &nbsp;&nbsp;<input type="submit" value="删 除" name="tijiao" onclick="SelectChk()">
<br><br>
<input type=hidden name="Bulletin">
</form>
</body>
</html>
View Code

7.BulletinSave.php        保存对公告的操作(删除,修改,添加等)

<?PHP include('isAdmin.php'); ?>
<html>
<head>
<title>保存公告</title>
</head>
<body>
<?PHP 
date_default_timezone_set("PRC");
  include('..\Class\Users.php');
  include('..\Class\Bulletin.php');
  //session_start();
  //得到动作参数,如果为add则表示创建公告,如果为update则表示更改公告
  $StrAction=$_GET["action"];
  // 读取当前用户信息
  $objUser = new Users();
  $objUser->GetUsersInfo($_SESSION["UserName"]);
  // 设置公告信息
  $objBul = new Bulletin();
  //取得公告题目和内容和提交人用户名
  $objBul->Title=$_POST["title"];
  $objBul->Content=$_POST["content"];
  $objBul->Poster=$objUser->Name;
  $objBul->PostTime=strftime("%Y-%m-%d %H:%M:%S");

  if ($StrAction=="add")
  {
    //在数据库表Board中插入新公告信息
    $objBul->insert();
  }
  else
  {
    //更改此公告信息
    $id=$_GET["id"];
    $objBul->update($id);
  } 

  print "<h3>公告成功保存</h3>";
?>
</body>
<script language="javascript">
  // 刷新父级窗口,延迟此关闭
  opener.location.reload();
  setTimeout("window.close()",800);
</script>
</html>
View Code

8.GoodsDelt.php        删除商品(管理员权限)

<?PHP include('isAdmin.php'); ?>
<html>
<head>
<title>删除商品信息</title>
</head>
<body>
<?PHP
  //只有管理员有强制删除商品的权限
  include('..\class\Goods.php');
  $gid=$_GET["gid"];
  $obj = new Goods();
  $obj->delete($gid);
  print("<h3>商品信息成功删除</h3>");
?>
</body>
<script language="javascript">
  // 刷新父级窗口,延迟此关闭
  opener.location.reload();
  setTimeout("window.close()",600);
</script>
</html>
View Code

9.GoodsList.php         商品管理页面(显示商品详细信息,管理员可执行删除操作)

<?PHP include('isAdmin.php'); ?>
<head>
<link href="../style.css" rel="stylesheet">
</head>
<?PHP 
  $m=0;
  $itype=$_GET["type"];
?>
<body>
<table border="1" width="100%" cellspacing="0" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF">
<tr><td bgcolor=#66CCFF height=24 colspan=2 align="center"><b>商品信息</b></td></tr></table>
<table border=1 width=100% cellspacing=0 bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF">
<tr  bgcolor="#CCFFFF">
<td align=center width="20%">商品名称</td>
<td align=center width="20%">卖家</td>
<td align=center width="20%">当前价格</td>
<td align=center width="20%">是否结束</td>
<td align=center width="20%">操作</td>
</tr>
<?PHP 
  include('..\Class\Goods.php');
  $obj = new Goods();
  $results = $obj->GetGoodslist(" WHERE TypeId=" . $itype);
  include('..\Class\Users.php');
  while($row = $results->fetch_row())
  {
    $m=$m+1;
    $objUser = new Users();
    $objUser->GetUsersInfo($row[15]);
?><tr>
  <td align=center><a href="../GoodsView.php?gid=<?PHP   echo($row[0]); ?>" target=_blank><?PHP   echo($row[3]); ?></a></td>
  <td align=center><a href="../UserView.php?uid=<?PHP   echo($row[15]); ?>"  target=_blank><?PHP   echo($objUser->Name); ?></a></td>  
  <td align=center><?PHP   echo($row[6]); ?></td>
  <td align=center><?PHP   if ($row[14]==1)
  {
?>已结束<?PHP   }
    else
  {
?>未结束<?PHP   } ?></td>
  <td align=center><a href="GoodsDelt.php?gid=<?PHP   echo($row[0]); ?>" onClick="if(confirm('确定删除商品?')){return this.href;}return false;" target=_blank>删除</a></td>
  </tr>  
<?PHP
} 
if ($m==0)
{
  print "<tr><td align=center colspan=5>没有商品</td></tr>";
} 
?>
</table>   
</body>
View Code

10.index.php          管理员登录后的主界面,采用了简单的框架

<?PHP include('isAdmin.php'); ?>
<html>

<head>
    <meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″> 
<title>二手交易市场系统后台管理</title>
</head>

<frameset framespacing="20" border="20" bordercolor= #333399  frameborder="1">
    <frameset cols="150,*">
        <frame name="contents" target="main" src="left.php" scrolling="auto" frameborder=0>
        <frame name="main" src="BulletinList.php" scrolling="auto" noresize frameborder=0>
    </frameset>
    <noframes>
    <body>

    <p>此网页使用了框架,但您的浏览器不支持框架。</p>

    </body>
    </noframes>
</frameset>

</html>
View Code

11.isAdmin.php         判断用户是否已登录且用户类型为管理员(UserType等于 1),若果不是,跳转到login.php

<?PHP
/*
从Session中获取注册用户信息,判断用户是否已登录且用户类型为管理员(UserType等于 1),若果不是,跳转到login.php
*/
  session_start();
  if ($_SESSION["UserType"]!=1)
  {
    header("Location: "."login.php");
  } 
?>
View Code

12.left.php            用于显示管理界面的左侧部分,定义了一系列的管理链接

<html>

<head>
<title>后台管理</title>
<link href="../style.css" rel="stylesheet">
<base target="main">
</head>

<body topmargin="4" leftmargin="4" bgcolor="#B8B8B8 ">       <!--bgcolor="#eeeeee":设置左边那部分的颜色-->
<div align="center">
  <center>
<table border="0" width="90%" height="300">
  <tr>
    <td width="100%" height="6"></td>
  </tr>
  <tr>
    <td width="100%" height="6"><font color="#000080">系统设置</font></td>
  </tr>
  <tr>
    <td width="100%"   height="6">&nbsp;<font color="#0000FF">  
      <a href="TypeList.php" target="main">商品分类</a></font></td>
  </tr>
  <tr>
    <td width="100%"  height="6">&nbsp;<font color="#0000FF">
    <a href="BulletinList.php">公告管理</a></font></td>
  </tr>
  <tr>
    <td width="100%"  height="6">&nbsp;</font></td>
  </tr>
  <tr>
    <td width="100%" height="6"><font color="#000080">商品管理</font></td>
  </tr>
<?PHP
  include('..\Class\GoodsType.php');
  $objType = new GoodsType();
  $results = $objType->GetGoodsTypelist();
  while($row = $results->fetch_row())  {
?>
 <tr>
    <td width="100%"  height="6">&nbsp;<font color="#0000FF">  
      <a href="GoodsList.php?type=<?PHP echo($row[0]); ?>" target="main"><?PHP   echo($row[1]); ?></a></font></td>
  </tr>
<?PHP 
    } 
?>
  <tr>
    <td width="100%"  height="6">&nbsp;</font></td>
  </tr>
  <tr>
    <td width="100%" height="6"><font color="#000080">用户管理</font></td>
  </tr>
  <tr>
    <td width="100%"  height="6">&nbsp;<font color="#0000FF">  
      <a href="UserList.php?flag=0" target="main">用户列表</a></font></td>
  </tr>
  <tr>
    <td width="100%"  height="6">&nbsp;<font color="#0000FF">
      <a href="AdminPwdChange.php" target="main">密码修改</a></font></td>
  </tr>

  <tr>
    <td width="100%" height="6"><font color="#000080"> <a href="logout.php" target="_parent">退出</font></td>     <!--target="_parent":退出系统时跳出frame框架-->
  </tr>

</table>
  </center>
</div>
</body>
</html>
View Code

13.Login.php           登录界面(管理员登录)

<?PHP
  //根据录入的用户信息查询数据
  session_start();
  include('../class/Users.php');
  @$AdminId=$_SESSION["UserName"];
  @$AdminPwd=$_SESSION["$UserPwd"];//加@避免提示
  if($AdminId!="")
  {
    $objUser = new Users();
    $objUser->GetUsersInfo($AdminId);
    if ($objUser->UserId!="" && $objUser->UserPwd==$AdminPwd && $objUser->UserType==1)
    {
      $_SESSION["UserType"]=1;
      header("Location: "."index.php");
    } 
  } 
?>
<html>
<head>
<title>管理员登录</title>
<link rel="stylesheet" href="../style.css">
</head>
<body>
<form name="myform" action="putSession.php" method="Post">
<br>
<table border="0" align="center">
<tr><td align=center><h2>管理员登录</h2></td></tr>
</table>
<table border="0" align="center">
     <tr>
      <td align="right">管理员账号:</td>
      <td><input maxLength="20" name="loginname" size="30"></td>
     </tr>
    <tr>
      <td align="right">管理员密码:</td>
      <td><input maxLength="20" name="password" size="30" type="password"></td>
    </tr>
    <tr>
     <td align="right">&nbsp;</td>
        <td align="center">&nbsp;</td>
    </tr>
    <tr>
     <td align="right">&nbsp;</td>
        <td align="center"><input type="submit" value=" 登 陆 "></td>
    </tr>

</table>
</form>
</body>
</html>
View Code

14.logout.php          退出处理,清空Session

<?PHP
    session_start();
    unset($_SESSION['UserId']);
    unset($_SESSION['UserPwd']);
    unset($_SESSION['UserType']);
    unset($_SESSION['Name']);

    header("Location: index.php");
?>
View Code

15.putSession.php         处理用户登录操作(将用户名和密码提交给 服务器)

<?PHP
  session_start();
  // 取输入的用户名和密码以及用户类别
  $UID=$_POST["loginname"];
  $PSWD=$_POST["password"];
  include('..\Class\Users.php');
  $objUser = new Users();
  $objUser->UserId=$UID;
  $objUser->UserPwd=$PSWD;
  // 判断用户名密码是否正确
  if($objUser->CheckUser())
  {
    // 把用户名和密码放入Session
    $objUser->GetUsersInfo($UID);
    $_SESSION["UserName"]=$UID;
    $_SESSION["UserPwd"]=$PSWD;
    $_SESSION["UserType"]=$objUser->UserType;
    header("Location: "."index.php");
  }
  else
  {
    header("Location: "."login.php");
  } 
?>
View Code

16.TypeList.php         商品分类管理界面以及处理操作

<?PHP include('isAdmin.php'); ?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>分类管理</title>
<link rel="stylesheet" href="../style.css">
<script language="javascript">
/*
function form_onsubmit(obj) 
{   
  ValidationPassed = true;  
  if(obj.ClsId.selectedIndex <0) {
    alert("请选择一级分类");
    ValidationPassed = false;
    return ValidationPassed;
  }    
  if(obj.txttitle.value == "") {
    alert("请输入分类名称");
    ValidationPassed = false;
    return ValidationPassed;
  }    
}
*/
function form_onsubmit1(obj) 
{   
  ValidationPassed = true;  
  if(obj.txttitle.value == "") {
    alert("请输入分类名称");
    ValidationPassed = false;
    return ValidationPassed;
  }    
}
</script>
</head>
<body link="#000080" vlink="#080080">
<form id="form1" name="form1" method="POST">
<?PHP 
  include('..\Class\GoodsType.php');
  include('..\Class\Goods.php');
  $objType = new GoodsType();
  $objGoods = new Goods();
  //处理添加、修改和删除操作
  $Soperate=$_GET["Oper"];
  $Operid=$_GET["tid"];
  //删除
  if($Soperate=="delete")
  {
    //判断商品表中是否存在此分类
    if ($objGoods->HaveGoodsType($Operid))
    {
      exit("此分类包含商品信息,不能删除!");
    } 

    $objType->delete($Operid);
    echo '<script type="text/javascript">alert("分类已经成功删除!");window.parent.frames.contents.location.reload();document.location="TypeList.php";</script>';
    //window.parent.frames.contents.location.reload();刷新框架内容,contents为框架名称name(index.php里面有定义)
    //exit("分类已经成功删除!");
   // header("Location: TypeList.php");
  }
  elseif ($Soperate=="add")   //添加
  {
    $Name=$_POST["txttitle"];
    //判断是否已经存在此分类名称
    if($objType->HaveGoodsType($Name))
    {
      echo("已经存在此分类名称!");
    }
    else
    {
      $objType->TypeName=$Name;
      $objType->insert();
      echo '<script type="text/javascript">window.parent.frames.contents.location.reload();document.location="TypeList.php";</script>';
    } 

  }
  elseif ($Soperate=="edit")
  {
    $Name=$_POST["txttitle"];
    //判断是否已经存在此分类名称
    if ($objType->HaveGoodsType($Name))
    {
      echo("已经存在此分类名称!");
    }
    else
    {
      $objType->TypeName=$Name;
      $objType->update($Operid);
      echo '<script type="text/javascript">window.parent.frames.contents.location.reload();document.location="TypeList.php";</script>';
    } 
  } 
?>
<p align='center'><font style="FONT-SIZE: 12pt"><b>商 品 分 类 管 理</b></font></p>
<center>
<table border="1" cellspacing="0" width="90%"   bordercolorlight="#4DA6FF" bordercolordark="#ECF5FF">
  <tr>
    <td width="30%" align="center" bgcolor="#eeeeee"><strong>分类名称</strong></td>
    <td width="20%" align="center" bgcolor="#eeeeee"><strong>修 改</strong></td>
    <td width="20%" align="center" bgcolor="#eeeeee"><strong>删 除</strong></td>
  </tr>
<?PHP 
  //读取分类数据
  $results = $objType->GetGoodsTypelist();
  $exist = false;
  //在表格中显示分类名称
  while($row = $results->fetch_row())
  {
    $exist = true;
?>
  <tr>
    <td><?PHP  echo($row[1]); ?></td>
    <td align="center"><a href="TypeList.php?Oper=update&tid=<?PHP echo($row[0]); ?>&name=<?PHP echo($row[1]); ?>">修 改</a></td>
    <td align="center"><a href="TypeList.php?Oper=delete&tid=<?PHP echo($row[0]); ?>&name=<?PHP echo($row[1]); ?>">删 除</a></td>
  </tr>
<?PHP } ?>
</table>
    <p align="center">  
<?PHP 
  if(!$exist)  //如果记录集为空,则显示“目前还没有记录”
  {
    echo("<tr><td colspan=4 align=center><font style='COLOR:Red'>目前还没有记录。</font></td></tr></table>");
  }
?>
</form>
<?PHP 
  //如果当前状态为修改,则显示修改的表单,否则显示添加的表单
  if($Soperate=="update")
  {
    $sTitle=$_GET["name"];
?>
    <form name="UFrom" method="post" action="TypeList.php?tid=<?PHP echo($Operid); ?>&Oper=edit">
    <div align="center">
    <input type="hidden" name="sOrgTitle" value="<?PHP   echo($sTitle); ?>">
    <font color="#FFFFFF"><b><font color="#000000">分类名称</font></b></font> 
    <input type="text" name="txttitle" size="20" value="<?PHP   echo($sTitle); ?>">
    <input type="submit" name="Submit" value=" 修 改 ">
    </div>
  </form>
<?PHP }
  else
  {
?>
<form name="AForm" method="post" action="TypeList.php?Oper=add">
  <p align="center">
  <font color="#FFFFFF"><b><font color="#000000">添加分类:</font></b></font> 
  &nbsp;&nbsp;分类名称:&nbsp;&nbsp;<input type="text" name="txttitle" size="20">
  <input type="hidden" name="sUpperId" value="0">&nbsp;&nbsp;
  <input type="submit" name="Submit" value=" 添 加 " onclick="return form_onsubmit1(this.form)">
  </p>
</form>
<?PHP } ?>

</BODY>
</HTML>
View Code

17.UserDelt.php         处理来自UserList.php的删除操作

<?PHP include('isAdmin.php'); ?>
<html>
<head>
<title>删除用户信息</title>
</head>
<body>
<?PHP
  //只有管理员有强制删除商品的权限
  include('..\class\Users.php');
  $UserId=$_GET["userid"];
  $obj = new Users();
  $obj->delete($UserId);
  print("<h3>用户信息成功删除</h3>");
?>
</body>
<script language="javascript">
  // 刷新父级窗口,延迟此关闭
  opener.location.reload();
  setTimeout("window.close()",600);
</script>
</html>
View Code

18.UserList.php          系统用户管理,显示用户列表信息和操作

<?PHP include('isAdmin.php'); ?>
<html>
<head>
<title>系统用户管理</title>
<link href="../style.css" rel="stylesheet">
<script language="JavaScript">
function newwin(url) {
  var newwin=window.open(url,"newwin","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=400,height=380");
  newwin.focus();
  return false;
}
</script>
</head>
<body link="#000080" vlink="#008080">
<h3 align="center">用户列表</h3>
<table width='90%' align=center cellspacing=0 cellpadding=0 border=1 bordercolor="#808080" bordercolordark="#FFFFFF" bordercolorlight="#4DA6FF">
<tr>
<td align="center" width='10%' bgcolor="#eeeeee"><b>用户名</b></td>
<td align="center" width='16%' bgcolor="#eeeeee"><b>真实姓名</b></td>
<td align="center" width='16%' bgcolor="#eeeeee"><b>地址</b></td>
<td align="center" width='16%' bgcolor="#eeeeee"><b>电子邮件</b></td>
<td align="center" width='20%' bgcolor="#eeeeee"><b>移动电话</b></td>
<td align="center" width='22%' bgcolor="#eeeeee"><b>操 作</b></td>
</tr>
<?PHP
  include('..\Class\Users.php');
  $obj = new Users();
  $results = $obj->GetUserslist();
  $rCount=0;
  //循环显示所有的用户数据,同时画出表格
  while($row = $results->fetch_row())
  {
    $rCount++;
?>
<tr>
<td align=center><?PHP   echo($row[0]);  /*用户名*/ ?></td>
<td align=center><?PHP   echo($row[2]); /*用户姓名*/?></td>
<td align=center><?PHP   echo($row[4]); /*地址*/?>&nbsp;</td> 
<td align=center><?PHP   echo($row[6]); /*Email*/?>&nbsp;</td>
<td align=center><?PHP   echo($row[8]); /*手机*/?>&nbsp;</td>
<td align="center">
<?PHP   if($row[0]!="Admin")//不是Admin的话就添加  删除  操作
  {
?>
<a href=UserDelt.php?userid=<?PHP     echo($row[0]); ?>  onClick="if(confirm('确定删除此用户?')){return newwin(this.href);}return false;">删除</a>
<?PHP   } ?>&nbsp;
</td>
</tr>

<?PHP 
  } 
  if($rCount==0)
  {
    print("<tr align='center'><td colspan=6><font color=red>目前还没有用户记录</font></td></tr>");
  }
  else
  {
    print "<tr align='center'><td colspan=6><font color=red>当前共有".trim($rCount)."条用户记录</font></td></tr>";
  } 
?>
</table>
</body>
</html>
View Code

 


 

images存放了用户上传的图片(商品图片)

1.GoodsAdd.php  用户添加商品界面

<?PHP include('isUser.php'); ?>
<?PHP
 // session_start();
  date_default_timezone_set('Asia/Chongqing'); //系统时间差8小时问题
?>
<html>
<head>
<title>添加商品</title>
<link href=../style.css rel=STYLESHEET type=text/css>
<Script Language="JavaScript">
//域校验
function CheckFlds(){
  if (document.form1.aname.value==""){
   alert("请输入拍卖品名称!");
   form1.aname.focus;
   return false;
  }
  var a,b;
  a = document.form1.atype.selectedIndex;
  if(document.form1.atype.value ==0){
    if (form1.anum.value!=1 ){
      alert("竞价拍卖的拍卖数量必须为1!");
      form1.anum.value = 1;
      return false;
    }
  }
  return true;
}
</Script>
</head>
<body>
<form action="GoodsSave.php?flag=<?PHP echo($_GET["flag"]);; ?>" method=post name=form1 onsubmit="return CheckFlds()">

<table align=center cellpadding=0 cellspacing=0 width=90% border=1 bordercolorlight="#4DA6FF" bordercolordark="#ECF5FF">
<tr><td align=center width=100% colspan=3 bgcolor=#eeeeee height=28><font color=#0000ff>
    添加商品信息</font></td></tr>
<tr><td align=right width=25% bgcolor=#eeeeee>商品名称:</td><td> </td><td align=left><input type=text name=aname></td></tr>
<tr><td align=right bgcolor=#eeeeee>所 有 者:</td><td> </td><td align=left><input type=text readonly name=ownerid value=<?PHP echo($_SESSION["user_name"]); ?>></td></tr>
<tr><td align=right bgcolor=#eeeeee>所属分类:</td><td> </td><td align=left>
<select size="1" name="typeid">
<?PHP
  include('..\Class\GoodsType.php');
  $tid=intval($_GET["tid"]);
  $obj = new GoodsType();
  $results = $obj->GetGoodsTypelist();
  while($row = $results->fetch_row())
  {
?><option value="<?PHP   echo($row[0]); ?>" <?PHP   if ($row[0]==$tid)
  {
?> selected <?PHP   } ?>><?PHP   echo($row[1]); ?></option>  
  <?PHP   } ?>  
</select>
</td></tr>
<tr><td align=right bgcolor=#eeeeee>添加时间:</td><td> </td><td align=left>
    <input type=text name=stime value="<?PHP echo(strftime("%Y-%m-%d %H:%M:%S")); ?>" readonly size="24"></td></tr>
<tr><td align=right bgcolor=#eeeeee>商品价格:</td><td> </td><td align=left><input type=text name=sprice></td></tr>
<tr><td align=right bgcolor=#eeeeee>新旧程度:</td><td> </td><td align=left><input type=text name=oldnew></td></tr>
<tr><td align=right bgcolor=#eeeeee>保  修:</td><td> </td><td align=left><input type=text name=repaired> </td></tr>
<tr><td align=right bgcolor=#eeeeee>发  票:</td><td> </td><td align=left><input type=text name=invoice> </td></tr>
<tr><td align=right bgcolor=#eeeeee>运  费:</td><td> </td><td align=left><input type=text name=carriage></td></tr>
<tr><td align=right bgcolor=#eeeeee>支付方式:</td><td> </td><td align=left><input type=text name=pmode></td></tr>
<tr><td align=right bgcolor=#eeeeee><?PHP @$SaleOrBuys=intval($_GET["flag"])+1;echo("SaleOrBuys: " . $SaleOrBuys); ?></td><td> </td><td align=left><input type=text name=someo></td></tr>
<tr>
    <td align=right bgcolor=#eeeeee>送货方式:</td><td> </td><td align=left><input type=text name=dmode></td>
</tr>
<tr><td align=right bgcolor=#eeeeee>图片文件:</td><td> </td><td align=left>
    <input type=text name=goodsimage></td></tr>
<tr><td align=right bgcolor=#eeeeee>商品描述:</td><td> </td>
<td align=left><textarea rows="2" name="adetail" cols="40"></textarea></td></tr>
<tr><td align=center colspan=3 bgcolor=#eeeeee height=30><input name=submit type=submit value=" 确 定 "></td></tr>
<tr><td align=center colspan=3 bgcolor=#eeeeee>
<iframe frameborder="0" height="40" width="100%" scrolling="no" src="upload.php" ></iframe>
<input type="hidden" name="upimage">
</td></tr>
</table>
</form>
</center>
</body>
</html>
View Code

2.GoodsDelt.php  处理用户删除商品操作

<?PHP include('isUser.php'); ?>
<html>
<head>
<link href=../style.css rel=STYLESHEET type=text/css>
</head>
<body>
<?php 
  //从数据库中批量删除信息
  //读取要删除的编号
  include('..\Class\Goods.php');
  $gid=$_GET["gid"];
  $obj = new Goods();
  $obj->delete($gid);
  print "删除成功!";
?>
</form>
</body>
<script language="javascript">
  opener.location.reload();
  setTimeout("window.close()",600);
</script>
</html>
View Code

3.GoodsEdit.php  处理用户修改商品信息操作

<html>
<head>
<title>编辑商品</title>
<link href=../style.css rel=STYLESHEET type=text/css>
<Script Language="JavaScript">
//域校验
function CheckFlds(){
  if (document.form1.aname.value==""){
   alert("请输入拍卖品名称!");
   form1.aname.focus;
   return false;
  }
  var a,b;
  a = document.form1.atype.selectedIndex;
  if(document.form1.atype.value ==0){
    if (form1.anum.value!=1 ){
      alert("竞价拍卖的拍卖数量必须为1!");
      form1.anum.value = 1;
      return false;
    }
  }
  return true;
}
</Script>
</head>
<body>
<?php 
  include('..\Class\Goods.php');
  $gid=intval($_GET["gid"]);
  $obj = new Goods();
  $obj->GetGoodsInfo($gid);
  //读取卖家信息
  include('..\Class\Users.php');
  $objUser = new Users();
  $objUser->GetUsersInfo($obj->OwnerId);
  //读取商品类型
  include('..\Class\GoodsType.php');
  $objType = new GoodsType();
  $objType->GetGoodsTypeInfo($obj->TypeId);
?>

<form action="GoodsSave.php?flag=<?php echo($obj->SaleOrBuy-1); ?>&action=edit&gid=<?php echo($gid); ?>" method=post name=form1 onsubmit="return CheckFlds()">
<center>
<table align=center cellpadding=0 cellspacing=0 width=60% border=1 bordercolorlight="#4DA6FF" bordercolordark="#ECF5FF">
<tr><td align=center width=100% colspan=3 bgcolor=#eeeeee height=28><font color=#0000ff>
    编辑商品信息</font></td></tr>
<tr><td align=right width=25% bgcolor=#eeeeee>商品名称:</td><td> </td><td align=left><input type=text name=aname value="<?php echo($obj->GoodsName); ?>"></td></tr>
<tr><td align=right bgcolor=#eeeeee>所 有 者:</td><td> </td><td align=left><input type=text name=ownerid value=<?php echo($objUser->Name); ?> readonly></td></tr>
<tr><td align=right bgcolor=#eeeeee>所属分类:</td><td> </td><td align=left>
<select size="1" name="typeid">
<?php 
  $tid=intval($_POST["tid"]);
  $objType1 = new GoodsType();
  $results = $objType1->GetGoodsTypelist();
  while($row = $results->fetch_row())
  {
?><option value="<?php   echo($row[0]); ?>" <?php   if($row[0]==@$objGoods->TypeId)
  {
?> selected <?php   } ?>><?php   echo($row[1]); ?></option>  
 <?php  } ?>  
</select>
</td></tr>
<tr><td align=right bgcolor=#eeeeee>添加时间:</td><td> </td><td align=left>
    <input type=text name=stime value="<?php echo($obj->StartTime); ?>" readonly size="24"></td></tr>
<tr><td align=right bgcolor=#eeeeee>商品价格:</td><td> </td><td align=left><input type=text name=sprice value="<?php echo($obj->Price); ?>"></td></tr>
<tr><td align=right bgcolor=#eeeeee>新旧程度:</td><td> </td><td align=left><input type=text name=oldnew value="<?php echo($obj->OldNew); ?>"></td></tr>
<tr><td align=right bgcolor=#eeeeee>保  修:</td><td> </td><td align=left><input type=text name=repaired value="<?php echo($obj->Repaired); ?>"> </td></tr>
<tr><td align=right bgcolor=#eeeeee>发  票:</td><td> </td><td align=left><input type=text name=invoice value="<?php echo($obj->Invoice); ?>"> </td></tr>
<tr><td align=right bgcolor=#eeeeee>运  费:</td><td> </td><td align=left><input type=text name=carriage value="<?php echo($obj->Carriage); ?>"></td></tr>
<tr><td align=right bgcolor=#eeeeee>支付方式:</td><td> </td><td align=left><input type=text name=pmode value="<?php echo($obj->PayMode); ?>"></td></tr>
<tr>
    <td align=right bgcolor=#eeeeee>送货方式:</td><td> </td><td align=left><input type=text name=dmode value="<?php echo($obj->DeliverMode); ?>"></td>
</tr>
<tr><td align=right bgcolor=#eeeeee>商品描述:</td><td> </td>
<td align=left><textarea rows="2" name="adetail" cols="40"><?php echo($obj->GoodsDetail); ?></textarea></td></tr>
<tr><td align=center colspan=3 bgcolor=#eeeeee height=30><input name=submit type=submit value=" 确 定 "></td></tr>
</table>
</form>
</center>
</body>
</html>
View Code

4.GoodsOver.php   处理用户将商品结束操作(下架)

<?PHP include('isUser.php'); ?>
<html>
<head>
<link href=../style.css rel=STYLESHEET type=text/css>
</head>
<body>
<?PHP 
  //从数据库中批量删除商品信息
  //读取要删除的公告编号
  include('..\Class\Goods.php');
  $gid=$_GET["gid"];
  $obj = new Goods();
  $obj->SetOver($gid);
  print("商品交易已结束!");
?>
</form>
</body>
<script language="javascript">
  opener.location.reload();
  setTimeout("window.close()",600);
</script>
</html>
View Code

5.GoodsSave.php    用于执行对商品的操作的保存

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<?PHP 
  include('isUser.php'); 
  session_start();
?>
<html>
<head>
<title>保存商品信息</title>
</head>
<body>
<?PHP 
  //得到动作参数,如果为add则表示添加操作,如果为edit则表示更改操作
  $StrAction=$_GET["action"];
  // 定义Goods对象,保存商品数据
  include('..\Class\Goods.php');
  $obj = new Goods();
  $obj->GoodsName=$_POST["aname"];
  $obj->TypeId=$_POST["typeid"];
  //$obj->SaleOrBuy=intval($_POST["flag"])+1;//$_POST["flag"]获取不到数据
  //http://zhidao.baidu.com/link?url=-yIyAt8Px6a9g9YN42dG__GHssnJhYg9LoG3JTJnfDMxyJzyHlolIxZMDZYHqLQ_zGnU8_8Z5oK7mB_gU0UNBU_fDNHo4KLuT04KiPATrSu
  //http://www.cnblogs.com/fengzheng126/archive/2012/04/21/2461376.html
  $obj->SaleOrBuy=intval($_GET["flag"])+1;
  $obj->GoodsDetail=$_POST["adetail"];
  $obj->Price=$_POST["sprice"];
  $obj->StartTime=$_POST["stime"];
  $obj->OldNew=$_POST["oldnew"];
  $obj->Invoice=$_POST["invoice"];
  $obj->Repaired=$_POST["repaired"];
  $obj->Carriage=$_POST["carriage"];
  $obj->PayMode=$_POST["pmode"];
  $obj->DeliverMode=$_POST["dmode"];
  $obj->OwnerId=$_SESSION["user_id"];
  if ($StrAction=="edit")
  {
    $gid=$_GET["gid"];
    $obj->update($gid);
  }
  else
  {
    $obj->ImageUrl=$_POST["goodsimage"];
    $obj->insert();
  } 
  print "<h3>商品信息成功保存</h3>";
?>
</body>
<script language="javascript">
  // 刷新父级窗口,延迟此关闭
  opener.location.reload();
  setTimeout("window.close()",600);
</script>
</html>
View Code

6.isUser.php    判断是否为已登录用户,若不是自要求访问者登录或者注册账号

<?PHP
  session_start();
?>
<?PHP 
  //从Session变量中读取注册用户信息,并连接到数据库验证
  include('..\Class\Users.php');
  $UserName=trim($_SESSION["user_id"]);
  $Pwd=trim($_SESSION["user_pwd"]);
  //如果用户名为空,则显示提示信息
  if($UserName=="")
  {
    exit("请登录后再使用!");
  }
  else
  {
    //连接数据库,进行身份验证
    $obj = new Users();
    $obj->UserId=trim($_SESSION["user_id"]);
    $obj->UserPwd=trim($_SESSION["user_pwd"]);
    if (!$obj->CheckUser())
    {
      exit("请登录后使用本系统!");
    } 
  } 
?>
View Code

7.PwdChange.php    修改用户密码界面

<?PHP include('isUser.php'); ?>
<link href="../style.css" rel="stylesheet">
<?PHP
  session_start();
  $uid=$_SESSION["user_id"];
?>
<html>
<head>
<title>修改密码</title>
</head>
<Script Language="JavaScript">
function ChkFields() {
  if (document.myform.OriPwd.value=='') {
    alert("请输入原始密码!")
    return false
  }
  if (document.myform.Pwd.value.length<6) {   
    alert("新密码长度大于等于6!")
    return false
  }
  if (document.myform.Pwd.value!=document.myform.Pwd1.value) {    
    alert("两次输入的新密码必须相同!")
    return false
  }
  return true
}
</Script>
<body>
<form method="POST" action="SavePwd.php?aid=<?PHP echo($uid); ?>" name="myform" onsubmit="return ChkFields()">
<p align="center">修改密码</p>
<table align="center" border="1" cellpadding="1" cellspacing="1" width="263" bordercolor="#008000" bordercolordark="#FFFFFF" height="134">
      <tr>
        <td align=left width="86" height="18">用户名</td>
    <td width="161" height="18"><?PHP echo($uid); ?></td>
    </tr>
    <tr>
      <td align=left width="86" height="23">原始密码</td>
        <td width="161" height="23"><input type="password" name="OriPwd"></td>
      </tr>
    <tr>
      <td align=left width="86" height="23">新密码</td>
        <td width="161" height="23"><input type="password" name="Pwd"></td>
      </tr>
    <tr>
      <td align=left width="86" height="23">密码确认</td>
        <td width="161" height="23"><input type="password" name="Pwd1"></td>
      </tr>
  </table> 
<p align="center">
<input type="submit" value=" 提 交 " name="B2"></p>
</form>  
</body>
</html>
View Code

8.SavePwd.php    保存修改后的用户密码

<?PHP  include('isUser.php');
  session_start();
  
  if (!$_SESSION["Passed"])
  {
    header("Location: ../index.php");
  } 
  $UserId=$_GET["uid"];
  ?>
<html>
<head>
<title>修改用户密码</title>
</head>
<body>
<?PHP 
  //session_start();
  $OriPwd=$_POST["OriPwd"];
  $Pwd=$_POST["Pwd"];
  //判断是否存在此用户
  include_once('..\Class\Users.php');
  $obj = new Users();
  $obj->UserId=$_SESSION["user_id"];
  $obj->UserPwd=$OriPwd;
  if($obj->CheckUser()==false)
  {
    print("不存在此用户名或密码错误!");
?>
  <Script Language="JavaScript">  
      setTimeout("history.go(-1)",1600);        
    </Script>
<?PHP 
  }
  else
  {
    $obj->UserPwd=$Pwd;
    $obj->setpwd($obj->UserId);
    print("<h2>更改密码成功!</h2>");
    $_SESSION["UserPwd"]=trim($Pwd);
?>  
<Script Language="JavaScript">
      setTimeout("window.close()",1600);
    </Script>
<?PHP
}
?>  
</body>
</html>
View Code

9.upfile.php     用于保存来自10.upload.php上传的图片,保存在user/images中,文件名用系统时间生成

<html>
<head>
<title>文件上传</title>
</head>
<body>
<?PHP 
    //'将当前的日期和时间转为文件名
    function makefilename() {
        // 获取当前系统时间,生成文件名
        $curtime = getdate();
        $filename =$curtime['year'] . $curtime['mon'] . $curtime['mday'] . $curtime['hours'] . $curtime['minutes'] . $curtime['seconds'] . ".jpeg";

        Return $filename;
    }


    // 检查上传文件的目录
    $upload_dir = getcwd() . "\\images\\";
    // 如果目录不存在,则创建
    if(!is_dir($upload_dir))
        mkdir($upload_dir);
    $newfilename = makefilename();
    $newfile = $upload_dir . $newfilename;
    if(file_exists($_FILES['file1']['tmp_name'])) {
        move_uploaded_file($_FILES['file1']['tmp_name'], $newfile);
    }
    else {
        echo("error");
    }
/*    echo("客户端文件名:" .    $_FILES['file1']['name'] . "<BR>");
    echo("文件类型:" . $_FILES['file1']['type'] . "<BR>");    
    echo("文件大小:" . $_FILES['file1']['size'] . "<BR>");    
    echo("服务器端临时文件名:" . $_FILES['file1']['tmp_name'] . "<BR>");
//    echo(    $_FILES['file1']['error'] . "<BR>");
    echo("上传后新的文件名:" . $newfile . "<BR>");
    //将文件信息传入内容字段*/
    echo("<SCRIPT>parent.document.form1.goodsimage.value='".$newfilename."'</SCRIPT>");//将文件信息传入内容字段
    echo("<font style='font-family: 宋体; font-size: 9pt'>图片上传成功 [ <a href=# onclick=history.go(-1)>修改图片</a> ]</font>");
?>
</body>
</html>
View Code

10.upload.php   用于用户上传商品图片

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
td {  font-size: 9pt}
a {  color: #000000; text-decoration: none}
a:hover {  text-decoration: underline}
.tx {  font-size: 9pt; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; height: 20px; width: 40px; background-color: #eeeeee; cursor: hand}
.bt {  font-size: 9pt; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; height: 16px; width: 60px; background-color: #eeeeee; cursor: hand}
.tx1 { height: 20px; width: 30px; font-size: 9pt; border: 1px solid; border-color: black black #000000; color: #0000FF}
-->
</style>
<title></title>
</head>
<body bgcolor=#eeeeee leftmargin="0" topmargin="0">
<form name="form1" method="post" action="upfile.php" enctype="multipart/form-data" >
<input type="hidden" name="act" value="upload">
<input type="hidden" name="filepath" value="images">
<table width="100%" border="0" cellspacing="0" bordercolordark="#CEE7FF" bordercolorlight="#000000">
<tr>
<td>商品图片上传
<input type="file" name="file1" style="width:68%"  class="tx1" value="">
<input type="submit" name="Submit" value="提 交" class="tx">
</td>
</tr>
</table>
</form>
</body>
</html>
View Code

11.UserAdd.php  用户注册界面

<html>
<head>
<link rel="stylesheet" href="../style.css">
<title>用户注册</title>
</head>
<script Language="JavaScript">
function ChkFields() {
    if (document.myform.userid.value=='') {
        window.alert ("请输入用户名!")
        myform.userid.focus()
        return false
    }
    if (document.myform.userid.value.length<=2) {
        window.alert ("请用户名长度必须大于2!")
        myform.userid.focus()
        return false
    }
    if (document.myform.username.value=='') {        
        window.alert ("请输入用户姓名!")
        myform.username.focus()
        return false
    }
    if (document.myform.email.value=='') {        
        window.alert ("请输入电子邮箱!")
        myform.email.focus()
        return false
    }
    if (document.myform.pwd.value.length<6) {        
        window.alert ("新密码长度大于等于6!")
        myform.pwd.focus()
        return false
    }
    if (document.myform.pwd.value=='') {        
        window.alert ("请输入新密码!")
        myform.pwd.focus()
        return false
    }
    if (document.myform.pwd1.value=='') {        
        window.alert ("请确认新密码!")
        myform.pwd1.focus()
        return false
    }
    if (document.myform.pwd.value!=document.myform.pwd1.value) {        
        window.alert ("两次输入的新密吗必须相同!")
        return false
    }
    return true
}
</script>
<body>
<form method="POST" action="UserSave.php" name="myform" onSubmit="return ChkFields()">
<h3></h3>
<p align="center">个人信息</p>
<input type="hidden" name="isadd" value="new">
 <table align="center" border="1" cellpadding="1" cellspacing="1" width="70%" bordercolor="#008000" bordercolordark="#FFFFFF">
      <tr>
        <td width="18%" align=left bgcolor="#CCFFCC">用户名</td>
        <td width="82%"><input type="text" name="userid" size="20"></td>
      </tr>
      <tr>
        <td align=left bgcolor="#CCFFCC">用户姓名</td>
        <td><input type="text" name="username" size="20"></td>
      </tr>
            <tr>
        <td align=left bgcolor="#CCFFCC">用户密码</td>
        <td><input type="password" name="pwd" size="20"></td>
      </tr>
      <tr>
        <td align=left bgcolor="#CCFFCC">密码确认</td>
        <td><input type="password" name="pwd1" size="20"></td>
      </tr>
      <tr>
        <td align=left bgcolor="#CCFFCC">性别</td>
        <td><select name="sex">
        <option value="0">男</option>
        <option value="1">女</option>
        </select></td>
      </tr>
      <tr>
        <td align=left bgcolor="#CCFFCC">通信地址</td>
        <td><input type="text" name="address" size="40"></td>
      </tr>
      <tr>
        <td align=left bgcolor="#CCFFCC">邮政编码</td>
        <td><input name="postcode" type="text" id="postcode" size="40"></td>
      </tr>
      <tr>
        <td align=left bgcolor="#CCFFCC">固定电话</td>
        <td><input type="text" name="telephone" size="40"></td>
      </tr>
      <tr>
        <td align=left bgcolor="#CCFFCC">移动电话</td>
        <td><input type="text" name="mobile" size="40"></td>
      </tr>
       <tr>
        <td align=left bgcolor="#CCFFCC">电子邮箱</td>
        <td><input type="text" name="email" size="40"></td>
      </tr>
  </table> 
<p align="center"><input type="submit" value=" 提 交 " name="B2"></p>
</form>  
</body>
</html>
View Code

12.UserSave.php     保存用户的注册信息到数据库中的users表中

<html>
<head>
<title>保存用户信息</title>
</head>
<body>
<?PHP 
  include('..\Class\Users.php');
  $objUser = new Users(); //创建User对象,用于访问个人信息表
  $uid=$_POST["userid"]; // 用户名
  $objUser->UserId=$uid; // 用户名
  $objUser->UserPwd=$_POST["pwd"]; // 密码
  $objUser->Name=$_POST["username"]; // 姓名
  $objUser->Sex=intval($_POST["sex"]); // 性别 
  $objUser->Address=$_POST["address"]; // 地址
  $objUser->Postcode=$_POST["telephone"]; // 邮编
  $objUser->Email=$_POST["email"]; // 电子邮件
  $objUser->Telephone=$_POST["telephone"]; // 电话
  $objUser->Mobile=$_POST["mobile"]; // 手机
  if ($_POST["isadd"]=="new")
  {
    //判断此用户是否存在
    if($objUser->HaveUsers($uid))
    {
?>
            <script language="javascript">
                alert("已经存在此用户名!");
                history.go(-1);
            </script>
<?PHP 
    }
    else
    {
      $objUser->UserType=0; // 用户类型
      $objUser->insert();
    } 
  }
  else
  {
    //更新用户信息
    $objUser->update($objUser->UserId);
  } 
  print "<h2>用户信息已成功保存!</h2>";
?>
</body>
<script language="javascript">
    opener.location.reload();
    setTimeout("window.close()",800);
</script>
</html>
View Code

13.UserView.php  用户界面,显示用户自己的转让或者求购的商品列表,对其进行管理

<html>
<head>
<link href=../style.css rel=STYLESHEET type=text/css>
<script language="javascript">
function newwin(url) {
  var oth="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left=200,top=100";
  oth = oth+",width=600,height=500";
  var newwin = window.open(url,"newwin",oth);
  newwin.focus();
  return false;
}
</script>
<title>用户商品列表</title>
</head>
<body>
<center>
<table border="0" width="760" cellspacing="0" cellpadding="0">
 <tr><td height="80"><img src="../images/title.jpg" border="0" width="800" height="100"></a></td></tr>
  <tr>
  <td bgcolor="#E1F5FF" height="19" valign="middle" align="left">
<?php 
  session_start();
  //读取参数, flag表示转让或求购类型
  @$flag=intval($_GET["flag"]);
  //设置转让或求购的查询条件
  if ($flag==0)
  {
    $cond=" WHERE SaleOrBuy=1";
  }
  else
  {
    $cond=" WHERE SaleOrBuy=2";
  } 
  //设置商品分类查询条件
  if (@$tid>0)  //tid 是什么 TypeId
  {
    $cond=$cond." AND TypeId=".$tid;
  } 
  // 只查看未结束的商品
  $uid=$_GET["uid"];
  $cond=$cond." AND OwnerId='".$uid."'";
  // 获取用户信息
  include('..\Class\Users.php');
  $objUser = new Users();
  $objUser->GetUsersInfo($uid);
  //创建Goods对象,读取满足条件的记录
  include('..\Class\Goods.php');
  $obj = new Goods();
  $results = $obj->GetGoodslist($cond);
  if ($flag==0)
  {
?>
   <B>转让信息</B>&nbsp;&nbsp;<a href="UserView.php?flag=1">求购信息</a>
  <?php }
  else
{
?>
   <a href="UserView.php?flag=0">转让信息</a>&nbsp;&nbsp;<B>求购信息</B>
  <?php } ?>   
  </td>  
  </tr>
<tr><td width="16%" valign="top" align="left"  bgcolor="#E1F5FF">
<table border="1" width="100%" cellspacing="1" bordercolorlight="#63CFFF" bordercolordark="#FFFFFF"  bgcolor="#E1F5FF">
<tr>
<td valign="top" colspan=2 align="center">
<table border=1 width=100% cellspacing=0 bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF">
<tr><td colspan=6 bgcolor="#FFFFFF">
    <p align="center"><font color=#3399FF><b>【<?php echo($objUser->Name); ?>的商品信息】</b></font></td></tr>

<tr>
<td align=center width="14%" bgcolor="#E1F5FF">商品图片</td>
<td align=center width="20%" bgcolor="#E1F5FF">商品名称</td>
<td align=center width="10%" bgcolor="#E1F5FF">价格</td>
<td align=center width="12%" bgcolor="#E1F5FF">新旧程度</td>
<td align=center width="10%" bgcolor="#E1F5FF">发布时间</td>
<td align=center width="12%" bgcolor="#E1F5FF">操作</td>

</tr>
<?php 
  $m=0;
  while($row = $results->fetch_row())
  {
?>
  <tr><td align=center bgcolor="#FFFFFF"><?php   if ($row[5]=="")
  {
?><img src="../images/noImg.jpg" height=50 border=0>
<?php   }
  else
  {
?><img src="images/<?php     echo($row[5]); ?>" height=50 border=0>
<?php   } ?></td>
  <td align=center bgcolor="#FFFFFF"><a href="../GoodsView.php?gid=<?php   echo($row[0]); ?>" target=_blank><?php   echo($row[3]); ?></a></td>
  <td align=center bgcolor="#FFFFFF"><?PHP   echo($row[6]); ?></td>
  <td align=center bgcolor="#FFFFFF"><?php   echo($row[8]); ?>&nbsp;</td>
  <td bgcolor="#FFFFFF" align="center"><?php   echo($row[7]); ?></td>
  <td align=center bgcolor="#FFFFFF">
  <?php   if ($row[14]==1)
  {
?>
    已结束
  <?php   }
    else
  {
?>
  <?php if ($row[15]==@$_SESSION["user_id"])
     {
?>
  <a href="GoodsEdit.php?gid=<?php echo($row[0]); ?>" target=_blank>修改</a>&nbsp;
  <a href="GoodsDelt.php?gid=<?php echo($row[0]); ?>" target=_blank>删除</a>&nbsp;
  <a href="GoodsOver.php?gid=<?php echo($row[0]); ?>" target=_blank>结束</a>
  <?php     } ?>
  <?php   } ?></td>
  </tr>  
<?php   $m=$m+1;
  } 
  if ($m==0)
  {
    echo("<tr><td bgcolor=#FFFFFF align=center colspan=6>暂无商品信息</td></tr>");
  } 
?>
</table>
</td>
</tr>
</table>
</body>
</html>
View Code

 


 

截图:

系统主界面:

管理员主界面:

 

点赞(0)

评论列表 共有 0 条评论

暂无评论
立即
投稿
发表
评论
返回
顶部