PageRenderTime 40ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/agency2/admin/editproduct.php

https://bitbucket.org/shikhaupadhyay/advt
PHP | 208 lines | 122 code | 84 blank | 2 comment | 9 complexity | 0ad7a4f761fb32a71760fca57b7e0fe2 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  1. <?php include('includes/header.php');
  2. $imgurl = $dbfn->siteUrl().'proimages/';
  3. if($_GET['id']){
  4. if($_POST['update'])
  5. {
  6. if($_FILES['image']['name'])
  7. {
  8. $name = time().$_FILES["image"]["name"];
  9. $tmp_name = $_FILES["image"]["tmp_name"];
  10. move_uploaded_file($tmp_name, "proimages/$name");
  11. $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']."'";
  12. }
  13. else
  14. {
  15. $updatequery="update products set cid='".$_POST['category']."',title='".$_POST['title']."',description='".$_POST['description']."',price='".$_POST['price']."',created_date=now() where id='".$_GET['id']."'";
  16. }
  17. mysql_query($updatequery);
  18. $ProductType = $_POST['vegtype'];
  19. $SpicyType = $_POST['spicetype'];
  20. //check for already added or not
  21. $sqlptype="select * from product_type where ProductId='".$_REQUEST['id']."'";
  22. $resptype=mysql_query($sqlptype);
  23. $numptype=mysql_num_rows($resptype);
  24. if($numptype>0)
  25. {
  26. $rowptype=mysql_fetch_array($resptype);
  27. $Query = "update product_type set ProductId = '".$_GET['id']."' , ProductsType = '".$ProductType."' , SpicyType = '".$SpicyType."' , AddDate = '".date('Y-m-d H:i:s')."' where Id='".$rowptype['Id']."'";
  28. mysql_query($Query);
  29. }
  30. else{
  31. $Query = "insert into product_type set ProductId = '".$_GET['id']."' , ProductsType = '".$ProductType."' , SpicyType = '".$SpicyType."' , AddDate = '".date('Y-m-d H:i:s')."'";
  32. mysql_query($Query);
  33. }
  34. echo "<script>window.location.href='products.php?msg=upd'</script>";
  35. }
  36. $selectquery="select * from products where id='".$_GET['id']."'";
  37. $result=mysql_query($selectquery) or die(mysql_error());
  38. $row=mysql_fetch_object($result);
  39. $selectcat = "select * from categories";
  40. $catquery=mysql_query($selectcat) or die(mysql_error());
  41. }
  42. ?>
  43. <aside class="right-side">
  44. <!-- Content Header (Page header) -->
  45. <section class="content-header">
  46. <h1>
  47. Products
  48. </h1>
  49. <ol class="breadcrumb">
  50. <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
  51. <li><a href="products.php">Products</a></li>
  52. <li class="active">Update Product</li>
  53. </ol>
  54. </section>
  55. <!-- Main content -->
  56. <section class="content">
  57. <div class="row">
  58. <!-- left column -->
  59. <div class="col-md-12">
  60. <!-- general form elements -->
  61. <div class="box box-primary">
  62. <div class="box-header">
  63. <h3 class="box-title">Update Product</h3>
  64. </div><!-- /.box-header -->
  65. <!-- form start -->
  66. <form role="form" action="" method="post" enctype="multipart/form-data" name="user-form">
  67. <?php echo $msg;?>
  68. <div class="box-body">
  69. <div class="form-group">
  70. <label for="exampleInputTitle">Title</label>
  71. <input type="text" class="form-control" placeholder="Enter title" style='width:65%' name="title" data-validation="required" value="<?php echo $row->title;?>">
  72. </div>
  73. <div class="form-group">
  74. <label for="exampleInputContent">Description</label>
  75. <textarea class="form-control" placeholder="Enter Content" style='width:65%' name="description"><?php echo $row->description;?></textarea>
  76. </div>
  77. <div class="form-group">
  78. <label for="exampleInputContent">Price</label>
  79. <input type="text" class="form-control" placeholder="Enter price" style='width:65%' name="price" value="<?php echo $row->price;?>">
  80. </div>
  81. <div class="form-group">
  82. <?php
  83. //selected values
  84. $sqltype="select * from product_type where ProductId=".$row->id;
  85. $restype=mysql_query($sqltype);
  86. $rowtype=mysql_fetch_array($restype);
  87. ?>
  88. <label for="vegtype">Type </label>
  89. <select name="vegtype">
  90. <option value ="0" <?php if($rowtype['ProductsType']==0){echo 'selected';}?>>Veg</option>
  91. <option value ="1" <?php if($rowtype['ProductsType']==1){echo 'selected';}?>>Non Veg</option>
  92. </select>
  93. </div>
  94. <div class="form-group">
  95. <label for="spicetype">Spice </label>
  96. <select name="spicetype">
  97. <option value ="0" <?php if($rowtype['SpicyType']==0){echo 'selected';}?>>Spicy</option>
  98. <option value ="1" <?php if($rowtype['SpicyType']==1){echo 'selected';}?>>Non Spicy</option>
  99. </select>
  100. </div>
  101. <div class="form-group">
  102. <label for="exampleInputContent">Select Category</label>
  103. <select name="category">
  104. <?php while($cat = mysql_fetch_object($catquery)){?>
  105. <option value="<?php echo $cat->id;?>" <?php if($cat->id==$row->cid){echo 'selected';}?>><?php echo $cat->title;?></option>
  106. <?php }?>
  107. </select>
  108. </div>
  109. <div class="form-group">
  110. <label for="exampleInputIcon">Image</label>
  111. <input type="file" class="form-control" name="image" style='width:65%; height: auto;' >
  112. <img src="<?php echo $row->image;?>" width="60" height="60"/>
  113. </div>
  114. </div><!-- /.box-body -->
  115. <div class="box-footer">
  116. <input type="submit" class="btn btn-primary" value="Update" name="update">
  117. </div>
  118. </form>
  119. </div><!-- /.box -->
  120. </div><!--/.col (left) -->
  121. </div> <!-- /.row -->
  122. </section><!-- /.content -->
  123. </aside><!-- /.right-side -->
  124. <?php include('includes/footer.php');?>