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


<?php
  $msg = "";

  
  
  
  
  
$product_title = $_POST['product_title'];
$product_price = $_POST['product_price'];
$product_description=$_POST['product_description'];   

  // If upload button is clicked ...
  if (isset($_POST['submit'])) {
  	// Get image name
  	$image = $_FILES['image']['name'];
  	// Get text
  	$image_text = mysqli_real_escape_string($con, $_POST['image_text']);
  			

  	// image file directory
  	$target = "product_upload_image/".basename($image);

  	//$sql = "INSERT INTO blog_post (image, title) VALUES ('$image', '$image_text')";
  	$sql = "INSERT INTO product_post(title, price, image, description) VALUES('$product_title','$product_price', '$image', '$product_description')";
  	// execute query
  	mysqli_query($con, $sql);

  	if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
  		$msg = "Data Submit successfully";
  	}else{
  		$msg = "Failed to upload image";
  	}
  }
  $result = mysqli_query($db, "SELECT * FROM product_post");
?>

<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" action="manage_product.php" 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" placeholder="Enter Product Name" class="form-control" required>
								</div>
								
								<div class="form-group">
									<label for="categories" class=" form-control-label">Price</label>
									<input type="text" name="product_price" placeholder="Enter Price" class="form-control" required>
								</div>
								
								<div class="form-group">
									<label for="categories" class=" form-control-label">Image</label>
									<input type="file" name="image" class="form-control" <?php echo  $image?>>
								</div>
								
								
								<div class="form-group">
									<label for="categories" class=" form-control-label">Description</label>
									<textarea name="product_description" placeholder="Enter Product description" class="form-control"></textarea>
								</div>
								
								
							   <button id="payment-button" name="submit" type="submit" class="btn btn-lg btn-info btn-block">
							   <span id="payment-button-amount">Submit</span>
							   </button>
							   <div class="field_error"><?php echo $msg?></div>
							</div>
						</form>
                     </div>
                  </div>
               </div>
            </div>
         </div>
         
<?php
require('footer.inc.php');
?>