Chinaunix首页 | 论坛 | 博客
  • 博客访问: 886016
  • 博文数量: 179
  • 博客积分: 1784
  • 博客等级: 上尉
  • 技术积分: 2712
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-05 22:20
  • 认证徽章:
个人简介

发上等愿,结中等缘,享下等福;择高处立,就平处坐,向宽处行。

文章分类

全部博文(179)

文章存档

2019年(12)

2018年(4)

2017年(3)

2016年(12)

2015年(22)

2014年(19)

2013年(26)

2012年(32)

2011年(49)

分类: LINUX

2011-11-20 12:41:40

后台添加产品代码

  1. <script language="JavaScript">


  2. </script>
  3. <form action="product_added.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
  4.       <table width="600" align=center border="0" cellspacing="0" cellpadding="5">
  5.         <tr>
  6.           <td width="120"><div align="right">产品名称</div></td>
  7.           <td width="480"><input name="name" type="text" id="name" /></td>
  8.         </tr>
  9.         <tr>
  10.           <td><div align="right">产品分类</div></td>
  11.           <td><select name="leixing" id="leixing">
  12.              <option >请选择...</option>
  13.              <option value="男包">男包</option>
  14.              <option value="女包">女包</option>
  15.              <option value="钱包">钱包</option>
  16.              <option value="休闲包">休闲包</option>
  17.              <option value="商务包">商务包</option>
  18.              <option value="特价包">特价包</option>
  19.                </select>
  20.             <a href="product_category.php"></a> </td>
  21.         </tr>
  22.         <tr>
  23.           <td><div align="right">产品现价</div></td>
  24.           <td><input name="xianjia" type="text" id="xianjia" /></td>
  25.         </tr>
  26.         <tr>
  27.           <td><div align="right">产品原价</div></td>
  28.           <td><input name="yuanjia" type="text" id="yuanjia" /></td>
  29.         </tr>
  30.         <tr>
  31.           <td><div align="right">上传产品图片</div></td>
  32.           <td><input type="hidden" name="MAX_FILE_SIZE" size="200000"/>
  33.             <input type="file" name="file" /></td>
  34.         </tr>
  35.         <tr>
  36.           <td> </td>
  37.           <td><input type="submit" name="Submit" value="提交" />
  38.             <input type="reset" name="Submit2" value="重置" /></td>
  39.         </tr>
  40.       </table>
  41.       
  42.     </form>

  43. <?php
  44. session_start();
  45. //上传产品图片
  46. $uploaddir = 'picture/'; //上传文件目录
  47. //$RandomNum = rand(0,10000000);
  48. $flname = $_FILES['file']['name'];
  49. $flnames = explode('.',$flname);
  50. $filename = $flnames[0].$RandomNum.'.'.$flnames[1];
  51. $uploadfile = $uploaddir . $filename;
  52. MOVE_UPLOADED_FILE($_FILES['file']['tmp_name'],$uploadfile);



  53. //将产品信息写入数据库
  54. //require("../inc/config.inc.php");
  55. $name = $_POST['name'];
  56. $leixing = $_POST['leixing'];
  57. $xianjia = $_POST['xianjia'];
  58. $yuanjia = $_POST['yuanjia'];
  59. $s_path = $uploadfile;
  60. $db = mysql_connect("localhost","root","654321") ;

  61.     mysql_select_db("product",$db);
  62. //判断是否输入为空
  63.    if($_POST['submit']) {
  64.     if($name=="" || $leixing=="" || $xianjia=="" || $yuanjia=="" || $shuliang=="" || $bianhao=="" || $s_path==""){    

  65.     echo "



    ";

  66.     echo "

    错误信息!

    "
    ;

  67.     echo "对不起,输入信息不能为空!
    "
    ;

  68.     echo "
    "
    ;

  69.     echo "";

  70.     echo "";

  71.     exit ;    
  72.       }
  73.    else {
  74.        $query = "insert into product(name,leixing,xianjia,yuanjia,shuliang,bianhao,s_path) values (\"$name\",\"$leixing\",\"$xianjia\",\"$yuanjia\",\"$s_path\")";
  75. //echo $query
  76.    $result = mysql_query($query) or die("mysql_error");
  77. }
  78. if ($result)
  79. {
  80.     echo "



    ";
  81.     echo "产品添加成功!点击此处继续添加
    "
    ;
  82.     echo "";
  83. }
  84. else
  85. {
  86.     echo "



    ";
  87.     echo "产品添加失败!
    "
    ;
  88.     echo "";
  89. }
  90. }
  91. ?>
前台显示代码
  1. <?Php
  2.          $db = mysql_connect("localhost","root","654321") ;

  3.      mysql_select_db("product",$db);
  4.          $query_list = "select * from product order by id desc limit 0,36";
  5.          $result_list = mysql_query($query_list);
  6.          /*$num = mysql_num_rows($result_list);*/
  7.          $i=0;
  8.          /*for($i;$i<$num;$i++) {*/
  9.                while ($row1 = mysql_fetch_object($result_list)){
  10.                       $id = $row1 -> id;
  11.                       $xianjia = $row1 -> xianjia;
  12.                       $picture = $row1-> s_path;
  13.                       $yuanjia = $row1-> yuanjia;
  14.                                         //echo $picture;
  15.     echo "

  16.           


  17.           


  18.           

  19.           
  20. 现价:$xianjia  原价:$yuanjia
    ";
  21.                                        
  22.                                         $i++;
  23.                                         if($i%3==0)
  24.                                         echo "";
  25.                                        
  26.     }


  27. ?>

阅读(1700) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
请登录后评论。

登录 注册