<?php

$dbhost = "localhost";
$dbuser = "onnobaza_ecomapp";
$dbpassword = "*#AHKer@24537#*";
$dbname = "onnobaza_ecomapp";

$a = rand(00,999999);
$b = rand(0,9999);
$c = rand(0,999);
$d = "IMG_".$a."_".$b."_".$c."_";

$e = rand(0,9999);
$f = rand(0,999);
$g = $e.$f;
$sku = "SKU - ".$g;

$date = date('d M, Y');



$con = mysqli_connect($dbhost, $dbuser, $dbpassword, $dbname);


if(isset($_POST['submit'])){
    
	$item_type = $_POST['item_type'];
	$product_title = $_POST['product_title'];
	$product_details = $_POST['product_details'];
	$product_rating = $_POST['product_rating'];
	$in_stock = $_POST['in_stock'];
	$regular_price = $_POST['regular_price'];
	$discount = $_POST['discount'];
	$special_price = $_POST['special_price'];
	
	
	
	//Cover Image Function
	$coverImage = $_FILES ['cover_img']['name'];
	$coverImageName = $d.$coverImage;
	$coverImageTemp = $_FILES ['cover_img']['tmp_name'];
	$uploadCoverImage = 'product-images/'.$coverImageName;
	
	
	
	$sql = "INSERT INTO public_product_list (product_sku, item_type, product_title, product_details, product_rating, in_stock, regular_price, discount, special_price, cover_img, slider1, entry_date)
	VALUES ('$sku', '$item_type', '$product_title', '$product_details', '$product_rating', '$in_stock', '$regular_price', '$discount', '$special_price', '$coverImageName', '$coverImageName', '$date')";
	
	$result = mysqli_query( $con,$sql );
	
	if($result) {
		move_uploaded_file($coverImageTemp,$uploadCoverImage);
		echo "Product Added Successfully";
	}
	else {
		echo "Something went wrong!";
	}
	
	
	
}

?>



<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST" enctype="multipart/form-data">

Item Type: <br>
<input type="text" name="item_type"><br><br>

Product Title: <br>
<input type="text" name="product_title"><br><br>

Product Details: <br>
<textarea name="product_details" placeholder='Write product description here...' rows='10' cols='50'></textarea><br><br>

Product Rating: <br>
<input type="text" name="product_rating"><br><br>

Stock Balance: <br>
<input type="text" name="in_stock"><br><br>

Regular Price: <br>
<input type="text" name="regular_price"><br><br>

Discount: <br>
<input type="text" name="discount"><br><br>

Special Price: <br>
<input type="text" name="special_price"><br><br>

Cover Image: <br>
<input type="file" name="cover_img"><br><br>

<input type="submit" name="submit" value="Add Product">




</form>