Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- include ( 'config.php' );
- require_once( 'class.db.php' );
- $database = DB::getInstance();
- if($_POST['rowid']) {
- $id = $_POST['rowid']; //escape string
- $query = "SELECT * FROM stock WHERE stock_id = $id";
- $results = $database->get_results( $query );
- foreach( $results as $row ){
- $cat_id = $row['cat_id'];
- $brand_id = $row['brand_id'];
- $p_id = $row['p_id'];
- ?>
- <form method="post" name="form">
- <input id="stock_id" name="stock_id" type="hidden" value="<?php echo $row['stock_id'];?>"/>
- <div class="col-xs-12 col-sm-12 col-md-12">
- <div class="form-group">
- <label class="control-label">CATEGORY</label>
- <select id="category" name="category" class="form-control">
- <?php
- $qex = "SELECT * FROM category";
- $rex = $database->get_results( $qex );
- foreach( $rex as $rowex ) {
- ?>
- <option value="<?php echo $rowex['cat_id']; ?>"<?php
- if ($cat_id == $rowex['cat_id'])
- echo 'selected'; ?>><?php echo $rowex['cat_name'];?></option>
- <?php
- }
- ?>
- </select>
- </div>
- </div>
- <div class="col-xs-12 col-sm-12 col-md-12">
- <div class="form-group">
- <label class="control-label">BRAND</label>
- <select id="brand" name="brand" class="switchable form-control">
- <?php
- $qex = "SELECT * FROM brand";
- $rex = $database->get_results( $qex );
- foreach( $rex as $rowex ) {
- ?>
- <option value="<?php echo $rowex['brand_id']; ?>"<?php
- if ($brand_id == $rowex['brand_id'])
- echo 'selected'; ?> class="brand_<?php echo $rowex['cat_id'];?>"><?php echo $rowex['brand_name'];?></option>
- <?php
- }
- ?>
- </select>
- </div>
- </div>
- <div class="col-xs-12 col-sm-12 col-md-12">
- <div class="form-group">
- <label class="control-label">PRODUCT NAME</label>
- <select id="product" name="product" class="switchable form-control">
- <?php
- $qex = "SELECT * FROM product";
- $rex = $database->get_results( $qex );
- foreach( $rex as $rowex ) {
- ?>
- <option value="<?php echo $rowex['product_id']; ?>"<?php
- if ($product_id == $rowex['product_id'])
- echo 'selected'; ?> class="product_<?php echo $rowex['brand_id'];?>"><?php echo $rowex['product_name'];?></option>
- <?php
- }
- ?>
- </select>
- </div>
- </div>
- <div class="col-xs-12 col-sm-12 col-md-12">
- <div class="form-group">
- <label class="control-label">IN STOCK</label>
- <input type="number" id="availability" name="availability" value="<?php echo $row['availability'];?>" class="form-control"/>
- </div>
- </div>
- <div class="clearfix"></div>
- <div>
- <input type="submit" value="Update Data" class="pull-right btn btn-primary submit" style="margin-right:15px;"/>
- <span class="pull-left error" style="display:none;margin-left:15px;"> Please Enter Valid Data</span>
- <span class="pull-left success" style="display:none;margin-left:15px;"> Data updated!</span>
- <div class="clearfix"></div>
- </div>
- </form>
- <?php
- }
- ?>
- <script type="text/javascript" >
- $(document).ready(function(){
- $(function() {
- $(".submit").click(function() {
- var stock_id = $("#stock_id").val();
- var category = $('select[name="category"]').val()
- var brand = $('select[name="brand"]').val()
- var product = $('select[name="product"]').val()
- var availability = $("#availability").val();
- var dataString =
- 'stock_id='+ stock_id +
- '&brand=' + brand +
- '&category=' + category +
- '&product=' + product +
- '&availability=' + availability
- ;
- if(
- stock_id=='' ||
- brand=='' ||
- category=='' ||
- product=='' ||
- availability==''
- ){
- $('.success').fadeOut(200).hide();
- $('.error').fadeOut(200).show();
- }
- else
- {
- $.ajax({
- type: "POST",
- url: "update-stock.php",
- data: dataString,
- success: function(){
- $('.success').fadeIn(200).show();
- $('.error').fadeOut(200).hide();
- }
- });
- }
- return false;
- });
- });
- $("#category").change(function () {
- if ($(this).data('options') == undefined) {
- $(this).data('options', $('select.switchable option').clone());
- }
- var id = $(this).val();
- var that = this;
- $("select.switchable").each(function () {
- var thisname = $(this).attr('name');
- var theseoptions = $(that).data('options').filter('.' + thisname + '_' + id);
- $(this).html(theseoptions);
- });
- });
- //then fire it off once to display the correct elements
- $('#category').trigger('change');
- });/** Document Ready Functions END **/
- </script>
- <?php } ?>
- <?php
- session_start();
- include ( 'config.php' );
- require_once( 'class.db.php' );
- $database = DB::getInstance();
- if($_POST) {
- $stock_id = $_POST['stock_id'];
- $brand = $_POST['brand'];
- $category = $_POST['category'];
- $product = $_POST['product'];
- $availability = $_POST['availability'];
- $update = array(
- 'p_id' => $product,
- 'brand_id' => $brand,
- 'cat_id' => $cat,
- 'availability' => $availability
- );
- $where_clause = array(
- 'stock_id' => $stock_id
- );
- $updated = $database->update( 'stock', $update, $where_clause, 1 );
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement