Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.15 KB | None | 0 0
  1. <?php
  2.  
  3. session_start();
  4. include ( 'config.php' );
  5. require_once( 'class.db.php' );
  6.  
  7. $database = DB::getInstance();
  8.  
  9. if($_POST['rowid']) {
  10. $id = $_POST['rowid']; //escape string
  11.  
  12. $query = "SELECT * FROM stock WHERE stock_id = $id";
  13. $results = $database->get_results( $query );
  14. foreach( $results as $row ){
  15. $cat_id = $row['cat_id'];
  16. $brand_id = $row['brand_id'];
  17. $p_id = $row['p_id'];
  18. ?>
  19.  
  20. <form method="post" name="form">
  21. <input id="stock_id" name="stock_id" type="hidden" value="<?php echo $row['stock_id'];?>"/>
  22.  
  23. <div class="col-xs-12 col-sm-12 col-md-12">
  24. <div class="form-group">
  25. <label class="control-label">CATEGORY</label>
  26. <select id="category" name="category" class="form-control">
  27. <?php
  28. $qex = "SELECT * FROM category";
  29. $rex = $database->get_results( $qex );
  30. foreach( $rex as $rowex ) {
  31. ?>
  32.  
  33. <option value="<?php echo $rowex['cat_id']; ?>"<?php
  34. if ($cat_id == $rowex['cat_id'])
  35. echo 'selected'; ?>><?php echo $rowex['cat_name'];?></option>
  36. <?php
  37. }
  38. ?>
  39. </select>
  40. </div>
  41. </div>
  42.  
  43. <div class="col-xs-12 col-sm-12 col-md-12">
  44. <div class="form-group">
  45. <label class="control-label">BRAND</label>
  46. <select id="brand" name="brand" class="switchable form-control">
  47. <?php
  48. $qex = "SELECT * FROM brand";
  49. $rex = $database->get_results( $qex );
  50. foreach( $rex as $rowex ) {
  51. ?>
  52. <option value="<?php echo $rowex['brand_id']; ?>"<?php
  53. if ($brand_id == $rowex['brand_id'])
  54. echo 'selected'; ?> class="brand_<?php echo $rowex['cat_id'];?>"><?php echo $rowex['brand_name'];?></option>
  55. <?php
  56. }
  57. ?>
  58. </select>
  59. </div>
  60. </div>
  61.  
  62. <div class="col-xs-12 col-sm-12 col-md-12">
  63. <div class="form-group">
  64. <label class="control-label">PRODUCT NAME</label>
  65. <select id="product" name="product" class="switchable form-control">
  66. <?php
  67. $qex = "SELECT * FROM product";
  68. $rex = $database->get_results( $qex );
  69. foreach( $rex as $rowex ) {
  70. ?>
  71. <option value="<?php echo $rowex['product_id']; ?>"<?php
  72. if ($product_id == $rowex['product_id'])
  73. echo 'selected'; ?> class="product_<?php echo $rowex['brand_id'];?>"><?php echo $rowex['product_name'];?></option>
  74. <?php
  75. }
  76. ?>
  77. </select>
  78. </div>
  79. </div>
  80.  
  81. <div class="col-xs-12 col-sm-12 col-md-12">
  82. <div class="form-group">
  83. <label class="control-label">IN STOCK</label>
  84. <input type="number" id="availability" name="availability" value="<?php echo $row['availability'];?>" class="form-control"/>
  85. </div>
  86. </div>
  87.  
  88. <div class="clearfix"></div>
  89. <div>
  90. <input type="submit" value="Update Data" class="pull-right btn btn-primary submit" style="margin-right:15px;"/>
  91. <span class="pull-left error" style="display:none;margin-left:15px;"> Please Enter Valid Data</span>
  92. <span class="pull-left success" style="display:none;margin-left:15px;"> Data updated!</span>
  93. <div class="clearfix"></div>
  94.  
  95. </div>
  96. </form>
  97. <?php
  98. }
  99. ?>
  100.  
  101. <script type="text/javascript" >
  102. $(document).ready(function(){
  103.  
  104. $(function() {
  105. $(".submit").click(function() {
  106. var stock_id = $("#stock_id").val();
  107. var category = $('select[name="category"]').val()
  108. var brand = $('select[name="brand"]').val()
  109. var product = $('select[name="product"]').val()
  110. var availability = $("#availability").val();
  111.  
  112. var dataString =
  113. 'stock_id='+ stock_id +
  114. '&brand=' + brand +
  115. '&category=' + category +
  116. '&product=' + product +
  117. '&availability=' + availability
  118. ;
  119.  
  120. if(
  121. stock_id=='' ||
  122. brand=='' ||
  123. category=='' ||
  124. product=='' ||
  125. availability==''
  126. ){
  127. $('.success').fadeOut(200).hide();
  128. $('.error').fadeOut(200).show();
  129. }
  130. else
  131. {
  132. $.ajax({
  133. type: "POST",
  134. url: "update-stock.php",
  135. data: dataString,
  136. success: function(){
  137. $('.success').fadeIn(200).show();
  138. $('.error').fadeOut(200).hide();
  139. }
  140. });
  141. }
  142. return false;
  143. });
  144. });
  145.  
  146.  
  147. $("#category").change(function () {
  148. if ($(this).data('options') == undefined) {
  149. $(this).data('options', $('select.switchable option').clone());
  150. }
  151. var id = $(this).val();
  152. var that = this;
  153. $("select.switchable").each(function () {
  154. var thisname = $(this).attr('name');
  155. var theseoptions = $(that).data('options').filter('.' + thisname + '_' + id);
  156. $(this).html(theseoptions);
  157. });
  158. });
  159. //then fire it off once to display the correct elements
  160. $('#category').trigger('change');
  161.  
  162. });/** Document Ready Functions END **/
  163. </script>
  164.  
  165. <?php } ?>
  166.  
  167. <?php
  168.  
  169. session_start();
  170. include ( 'config.php' );
  171. require_once( 'class.db.php' );
  172.  
  173. $database = DB::getInstance();
  174.  
  175. if($_POST) {
  176. $stock_id = $_POST['stock_id'];
  177. $brand = $_POST['brand'];
  178. $category = $_POST['category'];
  179. $product = $_POST['product'];
  180. $availability = $_POST['availability'];
  181.  
  182.  
  183. $update = array(
  184. 'p_id' => $product,
  185. 'brand_id' => $brand,
  186. 'cat_id' => $cat,
  187. 'availability' => $availability
  188. );
  189.  
  190. $where_clause = array(
  191. 'stock_id' => $stock_id
  192. );
  193.  
  194. $updated = $database->update( 'stock', $update, $where_clause, 1 );
  195. }
  196. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement