<?php
require('top.inc.php');
?>


<?php


$id = $_GET['id']; // get id through query string

$qry = mysqli_query($con,"select * from product_post where id='$id'"); // select query

$data = mysqli_fetch_array($qry); // fetch data

if(isset($_POST['update'])) // when click on Update button
{
   $product_title = $_POST['product_title'];
   $product_price = $_POST['product_price'];
   $product_description=$_POST['product_description']; 
   $image = $_FILES['image']['name'];
   
   $image_text = mysqli_real_escape_string($con, $_POST['image_text']);
  			

  	// image file directory
  	$target = "product_upload_image/".basename($image);
	
	move_uploaded_file($_FILES['image']['tmp_name'], $target);
	
    $edit = mysqli_query($con,"update product_post set title='$product_title', price='$product_price', image='$image', description='$product_description' where id='$id'");
	

  	
  	
  	if($edit)
    {
        mysqli_close($con); // Close connection
        header("location:product.php"); // redirects to all records page
        exit;
    }
   else
   {
       echo mysqli_error();
   } 
	
   	
}
?>

<div class="content pb-0">
            <div class="animated fadeIn">
               <div class="row">
                  <div class="col-lg-12">
                     <div class="card">
                        <div class="card-header"><strong>Article</strong><small> Form</small></div>
                        <form method="POST"  enctype="multipart/form-data">
							<div class="card-body card-block">
								<div class="form-group">
									<label for="categories" class=" form-control-label">Post Title</label>
									<input type="text" name="product_title" value="<?php echo $data['title'] ?>" class="form-control">
								</div>
								
								<div class="form-group">
									<label for="categories" class=" form-control-label">Author</label>
									<input type="text" name="product_price" value="<?php echo $data['price'] ?>" class="form-control">
								</div>
								
								<div class="form-group">
									<label for="categories" class=" form-control-label">Image</label>
									<input type="file" name="image" class="form-control" value="<?php echo $data['image'] ?>" required>
								</div>
								
								
								<div class="form-group">
									<label for="categories" class=" form-control-label">Description</label>
									<textarea rows="8" name="product_description" class="form-control"><?php echo $data['description'] ?></textarea>
								</div>
							
							   <input type="submit" name="update" value="Submit">
							   </button>
							</div>
						</form>
                     </div>
                  </div>
               </div>
            </div>
         </div>
         
<?php
require('footer.inc.php');
?>