/agency2/admin/editproduct.php
PHP | 208 lines | 122 code | 84 blank | 2 comment | 9 complexity | 0ad7a4f761fb32a71760fca57b7e0fe2 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
- <?php include('includes/header.php');
- $imgurl = $dbfn->siteUrl().'proimages/';
- if($_GET['id']){
- if($_POST['update'])
- {
- if($_FILES['image']['name'])
- {
- $name = time().$_FILES["image"]["name"];
- $tmp_name = $_FILES["image"]["tmp_name"];
- move_uploaded_file($tmp_name, "proimages/$name");
-
- $updatequery="update products set cid='".$_POST['category']."',title='".$_POST['title']."',description='".$_POST['description']."',price='".$_POST['price']."',image='".$imgurl.$name."',created_date=now() where id='".$_GET['id']."'";
- }
- else
- {
- $updatequery="update products set cid='".$_POST['category']."',title='".$_POST['title']."',description='".$_POST['description']."',price='".$_POST['price']."',created_date=now() where id='".$_GET['id']."'";
-
- }
-
- mysql_query($updatequery);
-
- $ProductType = $_POST['vegtype'];
- $SpicyType = $_POST['spicetype'];
- //check for already added or not
- $sqlptype="select * from product_type where ProductId='".$_REQUEST['id']."'";
- $resptype=mysql_query($sqlptype);
- $numptype=mysql_num_rows($resptype);
- if($numptype>0)
- {
- $rowptype=mysql_fetch_array($resptype);
- $Query = "update product_type set ProductId = '".$_GET['id']."' , ProductsType = '".$ProductType."' , SpicyType = '".$SpicyType."' , AddDate = '".date('Y-m-d H:i:s')."' where Id='".$rowptype['Id']."'";
- mysql_query($Query);
- }
- else{
- $Query = "insert into product_type set ProductId = '".$_GET['id']."' , ProductsType = '".$ProductType."' , SpicyType = '".$SpicyType."' , AddDate = '".date('Y-m-d H:i:s')."'";
- mysql_query($Query);
- }
- echo "<script>window.location.href='products.php?msg=upd'</script>";
-
- }
-
- $selectquery="select * from products where id='".$_GET['id']."'";
- $result=mysql_query($selectquery) or die(mysql_error());
- $row=mysql_fetch_object($result);
- $selectcat = "select * from categories";
- $catquery=mysql_query($selectcat) or die(mysql_error());
- }
- ?>
- <aside class="right-side">
- <!-- Content Header (Page header) -->
- <section class="content-header">
- <h1>
- Products
- </h1>
- <ol class="breadcrumb">
- <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
- <li><a href="products.php">Products</a></li>
- <li class="active">Update Product</li>
- </ol>
- </section>
- <!-- Main content -->
- <section class="content">
- <div class="row">
- <!-- left column -->
- <div class="col-md-12">
- <!-- general form elements -->
- <div class="box box-primary">
- <div class="box-header">
- <h3 class="box-title">Update Product</h3>
- </div><!-- /.box-header -->
- <!-- form start -->
- <form role="form" action="" method="post" enctype="multipart/form-data" name="user-form">
- <?php echo $msg;?>
- <div class="box-body">
- <div class="form-group">
- <label for="exampleInputTitle">Title</label>
- <input type="text" class="form-control" placeholder="Enter title" style='width:65%' name="title" data-validation="required" value="<?php echo $row->title;?>">
- </div>
-
- <div class="form-group">
- <label for="exampleInputContent">Description</label>
- <textarea class="form-control" placeholder="Enter Content" style='width:65%' name="description"><?php echo $row->description;?></textarea>
- </div>
- <div class="form-group">
- <label for="exampleInputContent">Price</label>
- <input type="text" class="form-control" placeholder="Enter price" style='width:65%' name="price" value="<?php echo $row->price;?>">
- </div>
-
- <div class="form-group">
- <?php
- //selected values
- $sqltype="select * from product_type where ProductId=".$row->id;
- $restype=mysql_query($sqltype);
- $rowtype=mysql_fetch_array($restype);
- ?>
- <label for="vegtype">Type </label>
- <select name="vegtype">
- <option value ="0" <?php if($rowtype['ProductsType']==0){echo 'selected';}?>>Veg</option>
- <option value ="1" <?php if($rowtype['ProductsType']==1){echo 'selected';}?>>Non Veg</option>
- </select>
- </div>
-
- <div class="form-group">
- <label for="spicetype">Spice </label>
- <select name="spicetype">
- <option value ="0" <?php if($rowtype['SpicyType']==0){echo 'selected';}?>>Spicy</option>
- <option value ="1" <?php if($rowtype['SpicyType']==1){echo 'selected';}?>>Non Spicy</option>
- </select>
- </div>
- <div class="form-group">
- <label for="exampleInputContent">Select Category</label>
- <select name="category">
- <?php while($cat = mysql_fetch_object($catquery)){?>
- <option value="<?php echo $cat->id;?>" <?php if($cat->id==$row->cid){echo 'selected';}?>><?php echo $cat->title;?></option>
- <?php }?>
- </select>
- </div>
- <div class="form-group">
- <label for="exampleInputIcon">Image</label>
- <input type="file" class="form-control" name="image" style='width:65%; height: auto;' >
- <img src="<?php echo $row->image;?>" width="60" height="60"/>
- </div>
-
-
- </div><!-- /.box-body -->
- <div class="box-footer">
- <input type="submit" class="btn btn-primary" value="Update" name="update">
- </div>
- </form>
- </div><!-- /.box -->
-
- </div><!--/.col (left) -->
-
- </div> <!-- /.row -->
- </section><!-- /.content -->
- </aside><!-- /.right-side -->
- <?php include('includes/footer.php');?>
-