商品管理录入管理系统

此为后台管理界面:

<?

 $con = mysql_connect("localhost","","");
 mysql_select_db("xinwen", $con);//test改为你的库名
 $k = ($_GET[k]) ? $_GET[k] : 1;
 $dir = array(1=>"添加类别","添加品牌","添加耗材","耗材列表");
 $title = "耗材管理";
 $rs = mysql_query("select * from first order by id");
 $karr = array();
 echo"<script LANGUAGE='JavaScript'>
   karr = [";
 while($row = @mysql_fetch_row($rs)){
  if(!$initkey) $initkey = $row[0];
  $key = $row[0];
  $karr[$key] = $row[1];
  echo"'$row[1]',";
 }
 $kn = count($karr);
 echo"''] /r/n kn=$kn /r/n ";
 $selk = ($_POST[selk]) ? $_POST[selk] : $_POST[selg];
 $selk = $selk ? $selk : $initkey;
 if($_GET["edid"]&&!$_POST["nosub"]){
  $rs1 = mysql_query("select * from products where id='$_GET[edid]'");
  $row1 = @mysql_fetch_array($rs1);
  $selk =$row1[groupid];
 }
 $rs = mysql_query("select id,name from second where groupid = '$selk' order by id");
 $barr = array();
 echo"barr = [";
 while($row = @mysql_fetch_row($rs)){
  $key = $row[0];
  $barr[$key] = $row[1];
  echo"'$row[1]',";
 }
    $bn = count($barr);
 echo"''] /r/n bn=$bn /r/n </script>/r/n";
 if($_POST["kname"]){
  mysql_query("insert into first set name='$_POST[kname]'");
  echo"<script LANGUAGE='JavaScript'>alert('新增类别已保存');location=location</script>"; return;
 }
 if($_POST["bname"]&&!$_POST["nosub"]){
  mysql_query("insert into second set groupid='$_POST[selk]',name='$_POST[bname]'");
  echo"<script LANGUAGE='JavaScript'>alert('新增品牌已保存');location=location</script>"; return;
 }
 if($_POST["nosub"]){
  echo"<script LANGUAGE='JavaScript'>
    function init(){
     document.form1.selk.value='$_POST[selk]'/r/n";
   if($_POST["nosub"]==2) echo"document.form1.selb.value='$_POST[selb]'/r/n"; 
  echo"}
  </script>/r/n";
  $onload = "onload='init()'";
 }else if($_GET["edid"]){
  echo"<script LANGUAGE='JavaScript'>
    function init(){
     obj=document.form1
     obj.selk.value='$row1[groupid]'
     for(i=0;i<obj.selb.options.length;i++){
      if(obj.selb.options[i].innerText=='$row1[pinpai]'){
       obj.selb.selectedIndex=i ; break;
      }
     } 
    }
  </script>/r/n";
  $onload = "onload='init()'";
 }
 if($_POST["p"]){
  echo"<script LANGUAGE='JavaScript'>
    function init(){
     document.form1.selp.value='$_POST[p]'
     document.form1.selg.value='$_POST[selg]'
     document.form1.selpp.value='$_POST[selpp]'
    }
  </script>/r/n";
  $onload = "onload='init()'";
 }
 if($_POST["xh"]&&!$_GET["edid"]){
  $rs = mysql_query("select name from second where id='$_POST[selb]' and groupid = '$_POST[selk]'");
  $row = @mysql_fetch_row($rs);
  mysql_query("insert into products set groupid='$_POST[selk]',pinpai='$row[0]',pid='$_POST[selb]',
   xinhao='$_POST[xh]',price='$_POST[price]',haocai='$_POST[haocai]'");
  echo"<script LANGUAGE='JavaScript'>alert('新增机型已保存');location=location</script>"; return;
 }else if($_POST["xh"]&&$_GET["edid"]){
  $rs = mysql_query("select name from second where id='$_POST[selb]' and groupid = '$_POST[selk]'");
  $row = @mysql_fetch_row($rs);
  mysql_query("update products set groupid='$_POST[selk]',pinpai='$row[0]',pid='$_POST[selb]',
   xinhao='$_POST[xh]',price='$_POST[price]',
   haocai='$_POST[haocai]' where id='$_GET[edid]'");
  echo"<script LANGUAGE='JavaScript'>alert('修改已保存');location='?k=4'</script>"; return;
 }
 if($_GET["del"]){
  mysql_query("delete from products where id='$_GET[del]'");
  echo"<script LANGUAGE='JavaScript'>alert('所选信息已删除');location='?k=4'</script>"; return;
 }
?>
<HTML>
<HEAD>
<TITLE><?= $title ?></TITLE>
<style>
 table { font-size:12px; }
 caption { font-weight:bold; font-size:20px; letter-spacing:20px; padding:10px; }
 span { cursor:hand; }
 input { border: solid 1; }
 th { letter-spacing:2px;}
</style>
<script LANGUAGE='JavaScript'>
 function chk_submit(obj){
  <? if($k==1){ ?>
   if(!obj.kname.value){
     alert("请输入类别名"); return;
   }
   for(i=0;i<kn;i++){
    if(karr[i]==obj.kname.value){
     alert("/n/n库中已存在您输入的类别名。/n/n不能提交。/n/n"); return;
    }
   }
  <? }else if($k==2){ ?>
   if(!obj.bname.value){
    alert("请输入品牌名"); return;
   }
   for(i=0;i<bn;i++){
    if(barr[i]==obj.bname.value){
     alert("/n/n库中同类别下已存在您输入的品牌名。/n/n不能提交。/n/n"); return;
    }
   }
  <? }else if($k==3){ ?>
    arr1 =new Array("xh","price","haocai")
    arr2 =new Array("适用机型","原价格","现价格","耗材")
    an = arr1.length
    for(i=0;i<an;i++){
     if(!eval("obj."+arr1[i]+".value")){
      alert("请输入"+arr2[i]); return; break;
     }
    }
  <? } ?>
  obj.submit()
 } 
</script>
</HEAD>
<BODY TOPMARGIN="10" LEFTMARGIN="0" <?= $onload  ?> bgcolor='#f6f6f6'>
<FORM METHOD="post" name=form1><INPUT TYPE="hidden" NAME="nosub">
<TABLE border=1 CELLPADDING="0" CELLSPACING="0" ALIGN="CENTER" HEIGHT="400" WIDTH="752" bgcolor=#ffffff>
 <caption><?= $title ?></caption>
 <TR>
  <TD width=120 VALIGN="TOP" bgcolor='#d4d4d4'>
   <TABLE WIDTH="100%" CELLPADDING="5" CELLSPACING="0">
    <TR><Th HEIGHT="20"></Th></TR>
    <TR><Th><span onclick="location='?k=1'"><?= $dir[1] ?></span></Th></TR>
    <TR><Th><span onclick="location='?k=2'"><?= $dir[2] ?></span></Th></TR>
    <TR><Th><span onclick="location='?k=3'"><?= $dir[3] ?></span></Th></TR>
    <TR><Th><span onclick="location='?k=4'"><?= $dir[4] ?></span></Th></TR>
   </TABLE>
  </TD>
  <TD VALIGN="TOP">
   <TABLE WIDTH='100%' CELLPADDING='<?= (($k==4)?2:5) ?>' CELLSPACING='1' <? if($k==4)echo"bgcolor='#373737'" ?>>
    <caption style='font-size:16'><?= ($_GET["edid"])?"编辑商品":$dir[$k] ?></caption>
<?
 switch($k){
  case 1:
   echo"<tr><td ALIGN='RIGHT' width=100>类别名</td>
     <td><INPUT NAME='kname'></td></tr>";
   break;
  case 2:
   echo"<tr><td ALIGN='RIGHT' width=100>类别</td>
     <td><select name='selk' onchange='nosub.value=1;submit()'>";
   foreach($karr as $key=>$val){
    echo"<option value='$key'>$val</option>";
   }
   echo"</select></td></tr>
    <tr><td ALIGN='RIGHT' width=100>品牌名</td>
     <td><INPUT NAME='bname'></td></tr>";
   break;
  case 3:
   echo"<tr><td ALIGN='RIGHT' width=100>类别</td>
     <td><select name='selk' onchange='nosub.value=1;submit()'>";
   foreach($karr as $key=>$val){
    echo"<option value='$key'>$val</option>";
   }
   echo"</select></td></tr>
    <tr><td ALIGN='RIGHT' width=100>品牌名</td>
     <td><select name='selb' onchange='nosub.value=2;submit()'>";
   foreach($barr as $key=>$val){
    echo"<option value='$key'>$val</option>";
   }
   echo"</select></td></tr>
    <tr><td ALIGN='RIGHT' width=100>适用机型</td>
     <td><INPUT NAME='xh' SIZE='50' value='".($_POST[xh]?$_POST[xh]:$row1[xinhao])."'></td></tr>
    <tr><td ALIGN='RIGHT' width=100>价格</td>
     <td><INPUT NAME='price' value='".($_POST[price]?$_POST[price]:$row1[price])."'></td></tr>
    <tr><td ALIGN='RIGHT' width=100>耗材</td>
     <td><INPUT NAME='haocai' value='".($_POST[haocai]?$_POST[haocai]:$row1[haocai])."'></td></tr>";
   break;
  case 4:
   $p = ($_POST[p]) ? $_POST[p] : 1;
   $lim = 25;
   $where = "where 1=1";
   if($_POST[selg]&&$_POST[selg]!="all") $where .= " and groupid='$_POST[selg]'";
   if($_POST[selpp]&&$_POST[selpp]!="all") $where .= " and pinpai='$_POST[selpp]'";
   $rs = mysql_query("select count(id) as rn from products $where");
   $rn = mysql_result($rs,0,"rn");
   $ps = ceil($rn/$lim);
   echo"<tr bgcolor='#d4d4d4'><th width=30>编号</th><th width=60>分类</th><th width=30>品牌</th><th>适用机型</th>
     <th width=60>耗材型号</th><th width=45>价格</th><th>编辑</th><th>删除</th></tr>";
   $rs = mysql_query("select * from products $where order by groupid desc,haocai desc limit ".($p-1)*$lim.",$lim");
   $haddata=false;
   while($row=@mysql_fetch_array($rs)){
    $haddata=true;
    $key = $row["groupid"];
    $bgcolor = ($lim++%2) ? "#ffffff" : "#f6f6f6";
    echo"<tr align=center bgcolor='$bgcolor' onmouseover=/"bgColor='#ffff80'/" onmouseout=/"bgColor='$bgcolor'/">
     <td>$row[id]</td><td>$karr[$key]</td><td >$row[pinpai]</td><td style='word-break:break-all'>$row[xinhao]</td>
     <td>$row[haocai]</td><td>$row[price]</td>
     <td><span style='color:blue;font-family:wingdings;font-size:16' TITLE='编辑'
      onclick=/"location='?k=3&edid=$row[id]'/">?</span></td>
     <td><span style='color:red;font-family:webdings;font-size:14' TITLE='删除'
      onclick=/"if(confirm('您确定要删除吗?'))location=location+'&del=$row[id]'/">r</span></td></tr>";
   }
   if(!$haddata) echo"<tr bgcolor='#ffffff'><td colspan=9>没有符合查询条件的数据!</td></tr>";
   echo"<tr bgcolor='#d4d4d4'><td colspan=9 align=right><INPUT TYPE='hidden' NAME='p' value='$p'>
    分类查询:<select name=selg onchange=/"selpp.selectedIndex=0;p.value=1;submit()/"><option value='all'>所有类别</option>";
    foreach($karr as $key=>$val){
     echo"<option value='$key'>$val</option>";
    }
    echo"</select>&nbsp;
    <select name=selpp onchange='p.value=1;submit()'><option value='all'>所有品牌</option>";
    if($_POST["selg"]&&$_POST["selg"]!=="all"){
     foreach($barr as $val){
      echo"<option value='$val'>$val</option>";
     }
    }
    echo"</select> &nbsp; &nbsp; &nbsp; &nbsp;
    共有数据{$rn}行/{$ps}页 &nbsp; &nbsp;";
    if($p>1) echo"<span onclick=/"form1.p.value=".($p-1).";submit()/">";
    echo"上一页</span> &nbsp;";
    if($p<$ps) echo"<span onclick=/"form1.p.value=".($p+1).";submit()/">";
    echo"下一页</span> &nbsp;
    <select onchange=/"p.value=value;submit()/" name='selp'>";
    for($i=1;$i<=$ps;$i++){ echo"<option value='$i'>第{$i}页</option>"; }
    echo"</select> &nbsp;</td></tr>";
   break;
  default: break;
 }
 if($k<4) echo"<tr><td ALIGN='center' colspan=2><INPUT type='button' value='提 交' onclick=/"chk_submit(this.form)/"></td></tr>";

?>
</TABLE>   
  </TD>
 </TR>
</TABLE></FORM>
</BODY>
</HTML>

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页