gildas-Milandou Posted May 22, 2023 Share Posted May 22, 2023 (edited) This is the error message that I got after trying to uploaded an images : Warning: move_uploaded_file(): The second argument to copy() function cannot be a directory in C:\xampp\htdocs\E-commerce-website\admin_area\insert_products.php on line 30 Warning: move_uploaded_file(): Unable to move 'C:\xampp\tmp\php887B.tmp' to './product_images/' in C:\xampp\htdocs\E-commerce-website\admin_area\insert_products.php on line 30 Warning: move_uploaded_file(): The second argument to copy() function cannot be a directory in C:\xampp\htdocs\E-commerce-website\admin_area\insert_products.php on line 31 Here is my PHP code : <?php include('../includes/connect.php'); if(isset($_POST['insert_product'])){ $product_title=$_POST['product_title']; $description=$_POST['description']; $product_keywords=$_POST['product_keywords']; $product_category=$_POST['product_category']; $product_brands=$_POST['product_brands']; $product_price=$_POST['product_price']; $product_status='true'; // Accessing images $product_image1=$_FILES['product_image1']['name']; $product_image2=$_FILES['product_image2']['name']; $product_image3=$_FILES['product_image3']['name']; // Accessing images tmp name $temp_image1=$_FILES['product_image1']['tmp_name']; $temp_image2=$_FILES['product_image2']['tmp_name']; $temp_image3=$_FILES['product_image3']['tmp_name']; //Checking empty condition if($product_title=='' or $description=='' or $product_keywords='' or $product_category='' or $product_brands='' or $product_price='' or $product_image1='' or $product_image2='' or $product_image3=''){ echo '<script>alert("Please fill all the available fields")</script>'; exit(); }else{ move_uploaded_file($temp_image1,"./product_images/$product_image1"); move_uploaded_file($temp_image2,"./product_images/$product_image2"); move_uploaded_file($temp_image3,"./product_images/$product_image3"); // Insert query $insert_products="insert into `products` (product_title,product_description, product_keywords,category_id,brand_id,product_image1,product_image2, product_image3,product_price,date,status) values('$product_title','$description','$product_keywords','$product_category', '$product_brands','$product_image1','$product_image2','$product_image3','$product_price',NOW(),'$product_status')"; $result_query=mysqli_query($con,$insert_products); if($result_query) { echo '<script>alert("Successfully inserted the products")</script>'; } } } And here my HTML code: <!DOCTYPE html> <html> <h1>Insert products</h1> <form action="" method="POST" enctype="multipart/form-data"> <div class=" form-group"> <label for="product_title">Product title</label> <input id="product_title" name="product_title" type="text" class="form-control" placeholder="Enter product title" autocomplete="off" required="required"> </div> <div class=" form-group"> <label for="description">Product description</label> <input id="description" name="description" type="text" class="form-control" placeholder="Enter product description" autocomplete="off" required="required"> </div> <div class=" form-group"> <label for="product_keywords">Product keywords</label> <input id="product_keywords" name="product_keywords" type="text" class="form-control" placeholder="Enter product keywords" autocomplete="off" required="required"> </div> <!-- Categories --> <div class="form-group"> <select name="product_category" id="" class="form-control product_category"> <option value="">Select a Category</option> <?php $select_query="select * from categories"; $result_query=mysqli_query($con,$select_query); while($row=mysqli_fetch_assoc($result_query)){ $category_title=$row['category_title']; $category_id=$row['category_id']; echo "<option value='$category_id'>$category_title</option>"; } ?> </select> </div> <!-- Brands --> <div class="form-group"> <select name="product_brands" class="form-control"> <option value="">Select a Brand</option> <?php $select_query="select * from brands"; $result_query=mysqli_query($con,$select_query); while($row=mysqli_fetch_assoc($result_query)){ $brand_title=$row['brand_title']; $brand_id=$row['brand_id']; echo "<option value='$brand_id'>$brand_title</option>"; } ?> </select> </div> <div class="form-group"> <label for="product_image1">Product image 1</label> <input type="file" class="form-control" id="product_image1" name="product_image1" required="required"> </div> <div class="form-group"> <label for="product_image2">Product image 2</label> <input type="file" class="form-control" id="product_image2" name="product_image2" required="required"> </div> <div class="form-group"> <label for="product_image3">Product image 3</label> <input type="file" class="form-control" id="product_image3" name="product_image3" required="required"> </div> <div class=" form-group"> <label for="product_price">Product title</label> <input id="product_price" name="product_price" type="text" class="form-control" placeholder="Enter product price" autocomplete="off" required="required"> </div> <div class="text-left"> <input type="submit" name="insert_product" class="btn btn-primary" value="Insert products"> </div> </form> </div> </div> </div> </div> </div> </div> <!--End --> </html> Edited May 22, 2023 by gildas-Milandou The text was too much. Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted May 22, 2023 Solution Share Posted May 22, 2023 15 minutes ago, gildas-Milandou said: if($product_title=='' or $description=='' or $product_keywords='' or $product_category='' or $product_brands='' or $product_price='' or $product_image1='' or $product_image2='' or $product_image3='') In the above, "=" should be "==". If you use "=" you assign "" to the variable clearing any value it had. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.