Hello so I am currently trying to build an ecommerce website as a project but when I try to insert a product into my database everything but the image gets inserted anybody who could give me any advice
in this problem will be a huge help. Below I posted the entire code in case there are any underlying problems but I think the problem is mostly in the product
image part of the code again thank you for any help because I have been stuck in this problem for a long time.
<?php
include('../includes/connect.php');
if(isset($_POST['insert_product'])){
$product_tile=$_POST['product_title'];
$product_description=$_POST['product_description'];
$product_keyword=$_POST['product_keyword'];
$product_categories=$_POST['product_categories'];
$product_brands=$_POST['product_brands'];
$product_price=$_POST['product_price'];
$product_status='true';
This is the php code:
$product_image = " ";
$tmp_image = " ";
if(!empty($_FILES["product_image"]["name"])){
$product_image = mysql_real_escape_string($_FILES["product_image"]["name"]);
$tmp_image = mysql_real_escape_string(move_uploaded_file($_FILES["product_image"]["tmp_name"]));
}
if($product_tile=='' or $product_description=='' or $product_keyword=='' or $product_categories=='' or $product_brands=='' or $product_image=='' or $product_price=='' ){
echo"alert('Please fill all the available fields')";
exit();
}else{
move_uploaded_file($tmp_image,"./product_image/$product_image");
$insert_product="insert into `products` (product_name,product_description,product_keyword,category_id,brand_id,product_image,product_price,date,status) values ('$product_tile','$product_description','$product_keyword','$product_categories','$product_brands','$productt_image','$product_price',
NOW(),'$product_status')";
$result_query=mysqli_query($con,$insert_product);}}
if($result_query){
echo"alert('Successfully inserted the product')";
}
?>
-----------------------------------------------------------------------------------------------------------
This is the html code:
Product Name
<input type="text" name="product_title" id="product_title" class="form-control"
placeholder="Enter product name" autocomplete="off" required>
<!-- description -->
<form action="" method="post" enctype="multipartform-data">
<label for="product_description" class="form-label">Product Description</label>
<input type="text" name="product_description" id="product_description" class="form-control"
placeholder="Enter product description" autocomplete="off" required>
</div>
<!-- keyword -->
<form action="" method="post" enctype="multipartform-data">
<label for="product_keyword" class="form-label">Product Keyword</label>
<input type="text" name="product_keyword" id="product_keyword" class="form-control"
placeholder="Enter product keyword" autocomplete="off" required>
<!-- categories -->
<select name="product_categories" class="form-select" id="">
<option value="">Select Categories</option>
<?php
$select_categories="Select * from `categories`";
$result_categories = mysqli_query($con,$select_categories);
while($row_data=mysqli_fetch_assoc($result_categories)){
$category_name=$row_data['category_name'];
$category_id=$row_data['category_id'];
echo " <option value='$category_id'>$category_name</option> ";
}
?>
</select>
<!-- brands -->
<select name="product_brands" class="form-select" id="">
<option value="">Select Brands</option>
<?php
$select_brands="Select * from `brands`";
$result_brands = mysqli_query($con,$select_brands);
while($row_data=mysqli_fetch_assoc($result_brands)){
$brand_name=$row_data['brand_name'];
$brand_id=$row_data['brand_id'];
echo " <option value='$brand_id'>$brand_name</option> ";
}
?>
</select>
<!-- Image -->
<form action="" method="post" enctype="multipartform-data">
<label for="product_image" class="form-label">Product Image</label>
<input type="file" name="product_image" id="product_image" class="form-control" autocomplete="off"
required>
<!-- price -->
<form action="" method="post" enctype="multipartform-data">
<label for="product_price" class="form-label">Product Price</label>
<input type="text" name="product_price" id="product_price" class="form-control"
placeholder="Enter product price" autocomplete="off" required>
<!-- submit -->
<form action="" method="post" enctype="multipartform-data">
<input type="submit" value="Insert Product" name="insert_product" class="btn btn-info mb-3 px-3">