PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/sua_hanghoa.php

http://webdienmay.googlecode.com/
PHP | 166 lines | 150 code | 11 blank | 5 comment | 25 complexity | e37cdef4a58c6f3bd85674d95308657b MD5 | raw file
  1. <?php
  2. ob_start();
  3. session_start();
  4. ob_clean();
  5. if(isset($_SESSION['username'])&&$_SESSION['level']==2){
  6. require("../includes/config.php");
  7. if(isset($_POST['ok'])){
  8. if($_POST['slloaihang'] == -1){
  9. echo "<div align='center'>Lŕm ?n ch?n lo?i hŕng</div>";
  10. }else{
  11. $sllh=$_POST['slloaihang'];
  12. }
  13. if($_POST['slcongty'] == -1){
  14. echo "<div align='center'>Lŕm ?n ch?n công ty</div>";
  15. }else{
  16. $slct=$_POST['slcongty'];
  17. }
  18. if($_POST['txtname'] == NULL){
  19. echo "<div align='center'>Lŕm ?n nh?p tęn m?t hŕng vŕo</div>";
  20. }else{
  21. $tenhang=$_POST['txtname'];
  22. }
  23. ////////////
  24. if($_POST['txtdongia'] == NULL){
  25. echo "<div align='center'>Lŕm ?n nh?p ??n giá vŕo</div>";
  26. }else{
  27. $dg=$_POST['txtdongia'];
  28. }
  29. if($_POST['txtmota'] == NULL){
  30. $mota="none";
  31. }else{
  32. $mota=$_POST['txtmota'];
  33. }
  34. if($_POST['txtghichu'] == NULL){
  35. $ghichu="none";
  36. }else{
  37. $ghichu=$_POST['txtghichu'];
  38. }
  39. ////////////
  40. if($_POST['filehinh']!=NULL){
  41. move_uploaded_file($_FILES['filehinh']['tmp_name'],"../images/".$_FILES['filehinh']['name']);
  42. $image="images/".$_FILES['filehinh']['name'];
  43. }else{
  44. $image="none";
  45. }
  46. if($tenhang && $slct && $sllh && $dg && $image && $mota && $ghichu){
  47. $sql="insert into hanghoa(idcongty,tenhang,mota,ngaycapnhat,dongia,urlhinh,ghichu) values('$slct','$tenhang','$mota','".$_POST['txtngaycapnhat']."','$dg','.$image.','$ghichu')";
  48. mysql_query($sql);
  49. mysql_close($conn);
  50. header("location:hanghoa.php");
  51. exit();
  52. }
  53. }
  54. ///////////////////////////// l?y th?i gian hi?n hŕnh////////////////////
  55. $now = time();
  56. $nowstr = date("d-m-Y", $now);
  57. $nowstr1 = date("Y-m-d", $now);
  58. ////////////////////// l?y giá tr? lo?i hŕng ???c ch?n trong select//////////////////////////////
  59. $sql="select * from loaihang where idloaihang='".$_GET["idloaihang"]."'";
  60. $query=mysql_query($sql);
  61. if (mysql_num_rows($query)>0)
  62. {
  63. $row=mysql_fetch_array($query);
  64. $idloaihang=$row["idloaihang"];
  65. }
  66. else
  67. {
  68. $idloaihang="";
  69. }
  70. ///////////////////////////////////////////////////
  71. ?>
  72. <link href="style.css" rel="stylesheet" name="text/css" />
  73. <form action="them_hanghoa.php" method="post">
  74. <center>
  75. <font size="5">S?a Hŕng Hóa</font>
  76. <table width="400">
  77. <tr>
  78. <td width="200">Lo?i hŕng:
  79. <td width="200">
  80. <select name="slloaihang" onChange="location.href='them_hanghoa.php?idloaihang='+this.value;">
  81. <option value="-1">Ch?n Lo?i Hŕng</option>
  82. <?php
  83. $sql="select * from loaihang order by tenloai ASC";
  84. $query=mysql_query($sql);
  85. while($row=mysql_fetch_assoc($query))
  86. {
  87. if($idloaihang==$row['idloaihang'])
  88. echo "<option value='".$row['idloaihang']."' selected>".$row['tenloai']."</option>";
  89. else
  90. echo "<option value='".$row['idloaihang']."'>".$row['tenloai']."</option>";
  91. }
  92. ?>
  93. </select>
  94. </td>
  95. </tr>
  96. <tr>
  97. <td width="200">Công Ty:
  98. <td width="200">
  99. <select name="slcongty" >
  100. <?php
  101. $sql="select * from congty where idloaihang='".$idloaihang."'order by tencongty ASC";
  102. $query=mysql_query($sql);
  103. if( mysql_num_rows($query)!=0)
  104. {
  105. echo "<option value='-1'>Ch?n Công Ty</option>";
  106. while($row=mysql_fetch_assoc($query))
  107. {
  108. echo "<option value='".$row['idcongty']."' >".$row['tencongty']."</option>";
  109. }
  110. }
  111. else
  112. echo "<option value='-1'>Không có công ty</option>";
  113. ?>
  114. </select>
  115. </td>
  116. </tr>
  117. <tr>
  118. <td width="200">Tęn M?t Hŕng:
  119. <td width="200"><input type="text" name="txtname" size="25" /> </td>
  120. </tr>
  121. <tr>
  122. <td width="200"> T?:
  123. <td width="200"><textarea name="txtmota" cols=25 rows=10 ></textarea></td>
  124. </tr>
  125. <tr>
  126. <td width="200">Ngŕy c?p nh?t:
  127. <td width="200"><input type="text" name="txtngaycapnhat1" size="25" disabled="disabled" value="<?php echo $nowstr;?>" /> </td>
  128. <td><input type="hidden" name="txtngaycapnhat" size="25" value="<?php echo $nowstr1;?>" /> </td>
  129. </tr>
  130. <tr>
  131. <td width="200">??n giá:
  132. <td width="200"><input type="text" name="txtdongia" size="25" /> </td>
  133. </tr>
  134. <tr>
  135. <td width="200">Hěnh:
  136. <td width="200"><input type="file" name="filehinh" id="filehinh" size="20" /> </td>
  137. </tr>
  138. <tr>
  139. <td width="200">Ghi chú:
  140. <td width="200"><input type="text" name="txtghichu" size="25" /> </td>
  141. </tr>
  142. <tr>
  143. <td colspan="2" align="center"> <input type="submit" name="ok" value="Thęm" /> <a href=hanghoa.php> <input type="button" name="btnhanghoa" value="Quay L?i" /></a> </td>
  144. </tr>
  145. </table>
  146. </center>
  147. </form>
  148. <?php
  149. }
  150. else
  151. {
  152. header("location:login.php");
  153. exit();
  154. }
  155. ?>