D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home2
/
technoi4
/
www
/
demo
/
admin
/
Filename :
product_edit.php
back
Copy
<?php require_once('header.php'); require('config.php'); ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Update Product</title> </head> <?php include('sidebar.php'); ?> <!-- sidebar-wrapper --> <main class="page-content"> <div class="container"> <?php $ii = $_GET['pid']; $query = "SELECT product.*, brand.id as bid, brand.brand_name, categary.id as cid, categary.categary_title FROM `product` LEFT JOIN categary ON product.cid=categary.id LEFT JOIN brand ON product.bid=brand.id where product.pid=$ii"; $res = mysqli_query($conn, $query); $data = mysqli_fetch_assoc($res); mysqli_error($conn); ?> <form method="post" enctype="multipart/form-data"> <div class="row"> <div class="col-md-12"> <input type="hidden" name="oi" value="<?php echo $ii; ?>"> <div> <img src="img/product/<?php echo $data['image']; ?>" alt="" height="200px" width="200px"> </div> <div class="form-group"> <label for="exampleInputPassword1">Categary_Name</label> <select class="form-control" name="cid"> <option value="<?php echo $data['cid']; ?>"> <?php echo $data["categary_title"]; ?> </option> <option value="">Select Categary_Name</option> <?php require('config.php'); $result = mysqli_query($conn,"SELECT * FROM categary"); while($row = mysqli_fetch_array($result)) { ?> <option value="<?php echo $row['id'];?>"><?php echo $row["categary_title"];?></option> <?php } ?> </select> </div> <div class="form-group"> <label for="exampleInputPassword1">Brand_Name</label> <select class="form-control" name="bid"> <option value="<?php echo $data['bid']; ?>"> <?php echo $data["brand_name"]; ?> </option> <option value="">Select Brand_Name</option> <?php require('config.php'); $result = mysqli_query($conn,"SELECT * FROM brand"); while($row = mysqli_fetch_array($result)) { ?> <option value="<?php echo $row['id'];?>"><?php echo $row["brand_name"];?></option> <?php } ?> </select> </div> <div class="form-group"> <label for="exampleI">Product Name</label> <input type="text" class="form-control" name="product_name" value="<?php echo $data['product_name']; ?>"> </div> <div class="form-group"> <label for="exampleI">Description</label> <textarea class="form-control" id="editor" name="product_desc"><?php echo $data['product_desc']; ?></textarea> </div> <div class="form-group"> <label for="exampleFormControlFile1">Upload Image</label> <input type="file" class="form-control-file" id="exampleFormControlFile1" name="newimg"> </div> </div> </div> <button name="update" class="btn btn-primary">Update</button> </form> <script> $('#selector').change(function(){ if($(this).val() == "no" ){ $('.otherprof').slideUp(); }else{ $('.otherprof').slideDown(); } }); </script> <script> $('#selector_new').change(function(){ if($(this).val() == "no" ){ $('.other_prof').slideUp(); }else{ $('.other_prof').slideDown(); } }); </script> <?php if (isset($_POST['update'])) { $oi = $_POST['oi']; $cid = $_POST['cid']; $bid = $_POST['bid']; $product_name = $_POST['product_name']; $product_desc = addslashes($_POST['product_desc']); $newimg = $_FILES['newimg']['name']; if (!empty($newimg) && isset($newimg)!=NULL) { $dir = 'img/product/'; $extension = array("jpeg", "jpg", "png", "gif", "JPG"); $ext = pathinfo($_FILES["newimg"]["name"], PATHINFO_EXTENSION); $newimg = $_FILES['newimg']['name']; require('config.php'); if (in_array($ext, $extension)) { $query = "UPDATE `product` SET `cid`='$cid', `bid`='$bid', `product_name`='$product_name', `product_desc`='$product_desc', `image`='$newimg' where pid='$oi'"; $res = mysqli_query($conn, $query); if ($res) { move_uploaded_file($_FILES['newimg']['tmp_name'], "$dir" . $newimg); echo '<script type="text/JavaScript"> window.location="product.php"</script>'; } else echo "eror = " . mysqli_error($conn); } else { echo "Please, Select the file from the following extension: jpeg, jpg, png, gif"; } } else { $query = "UPDATE `product` SET `cid`='$cid', `bid`='$bid', `product_name`='$product_name', `product_desc`='$product_desc' where pid='$oi'"; $res = mysqli_query($conn, $query); if ($res) { echo '<script type="text/JavaScript"> window.location="product.php"</script>'; } } } ?> </div> </main> <!-- page-content" --> <?php include('footer.php'); ?>