<!DOCTYPE>
<?php
include("includes/dbconfig.php")
?>
<html>
<head>
<title>Inserting Product</title>
</head>
<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
<script>tinymce.init({ selector:'textarea' });</script>
<body bgcolor="skyblue">
<form action = "insert_product.php" method="post" enctype="multipart/form-data">
<table align="center" width="700" border="2" bgcolor="orange" >
<tr align = "center">
<td colspan="8"><h2>Insert New Product Here</h2></td>
</tr>
<tr>
<td align="right"><b>Product Title:</b></td>
<td><input type = "text" name="product_title" size="60" required/></td>
</tr>
<tr>
<td align="right"><b>Product Category:</b></td>
<td>
<select name="product_cat" required>
<option>Select a Category</option>
<?php
$get_cats = "SELECT * FROM categories";
$run_cats = mysqli_query($con, $get_cats);
while ($row_cats = mysqli_fetch_array($run_cats)){
$cat_id = $row_cats['cat_id'];
$cat_title = $row_cats['cat_title'];
echo"<option value ='$cat_title'>$cat_title</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td align="right"><b>Product Brand:</b></td>
<td>
<select name="product_brand" required>
<option>Select a Brand</option>
<?php
$get_brands = "SELECT * FROM brands";
$run_brands = mysqli_query($con, $get_brands);
while ($row_brands = mysqli_fetch_array($run_brands)){
$brand_id = $row_brands['brand_id'];
$brand_title = $row_brands['brand_title'];
echo"<option value='$brand_title'>$brand_title</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td align="right"><b>Product Image:</b></td>
<td><input type = "file" name="product_img" required/></td>
</tr>
<tr>
<td align="right"><b>Product Price:</b></td>
<td><input type = "text" name="product_price" required/></td>
</tr>
<tr>
<td align="right"><b>Product Description:</b></td>
<td><textarea name="product_desc" cols = "20" rows = "10"></textarea></td>
</tr>
<tr>
<td align="right"><b>Product Keywords:</b></td>
<td><input type = "text" name="product_keywords" size = "50" required/></td>
</tr>
<tr align="center">
<td colspan="8"><input type = "submit" name="insert_post" value="Add Product" /></td>
</tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['insert_post'])){
//get text data from fields
$product_title = $_POST['product_title'];
$product_cat = $_POST['product_cat'];
$product_brand = $_POST['product_brand'];
$product_price = $_POST['product_price'];
$product_desc = $_POST['product_desc'];
$product_keywords= $_POST['product_keywords'];
$insert_product = "INSERT into products(product_cat, product_brand, product_title, product_price, product_img, product_desc, product_keywords) VALUES ('$product_cat', '$product_brand', '$product_title', '$product_price', '$product_img', '$product_desc', '$product_keywords')";
$insert_pro = mysqli_query($con, $insert_product);
if($insert_pro){
echo "<script>alert('Product has been inserted')</script>";
echo "<script>window.open('insert_product.php','_self')</script>";
}
}
?>
I am trying to add an image. As you can see on it is supposed to display a alert message stating "product has been inserted" when I removed everything that had to do with product_img it uploaded properly when i include product_img it just empties out all the fields and that's it.