Untitled

 avatar
unknown
php
2 years ago
9.6 kB
12
Indexable
<?php 

include('../includes/connect.php');
if(isset($_POST['insert_product'])){

    $shoe_name=$_POST['shoe_name'];
    $shoe_description=$_POST['shoe_description'];
    $shoe_keywords=$_POST['shoe_keywords'];
    
    $shoe_category=$_POST['shoe_category'];
    $shoe_brand=$_POST['shoe_brand'];
    $shoe_price=$_POST['shoe_price'];
    $shoe_status="true";
    
    //CHECK BOX
    $checkbox1=$_POST['shoesizes'];
    $chk="";

    foreach($checkbox1 as $chk1){
        $chk .= $chk1.",";
    }
        

    //access images
    $shoe_image1=$_FILES['shoe_image1']['name'];
    $shoe_image2=$_FILES['shoe_image2']['name'];
    $shoe_image3=$_FILES['shoe_image3']['name'];
    
    //access temp image
    $temp_image1=$_FILES['shoe_image1']['tmp_name'];
    $temp_image2=$_FILES['shoe_image2']['tmp_name'];
    $temp_image3=$_FILES['shoe_image3']['tmp_name'];

    //checking empty condition
    if($shoe_name==''or $shoe_description=='' or $shoe_keywords=='' or $shoe_brand=='' or $shoe_category=='' or $shoe_image1=='' or $shoe_image2=='' or $shoe_image3=='' or $chk==''){
        echo "<script>alert('Product insertion fields incomplete, try again')</script>";
        exit();
    } else {
        move_uploaded_file($temp_image1, "./product_images/$shoe_image1");
        move_uploaded_file($temp_image2, "./product_images/$shoe_image2");
        move_uploaded_file($temp_image3, "./product_images/$shoe_image3");

        //insert query
        $insert_shoeproduct = "insert into `products` (shoe_name,shoe_description,shoe_keywords,category_id,brand_id,shoe_image1,shoe_image2,shoe_image3,shoe_price,date,status,shoesizes_num) values('$shoe_name','$shoe_description','$shoe_keywords','$shoe_category','$shoe_brand','$shoe_image1','$shoe_image2','$shoe_image3','$shoe_price',NOW(),'$shoe_status','$chk')";

        $result=mysqli_query($conn,$insert_shoeproduct);
        if($result){
            echo "<script>alert('Product Inserted!')</script>";
        }
    }


}
?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Insert Shoe Product - Admin Only</title>
     <!--external css-->
     <link rel="stylesheet" href="../cssfiles/main.css">
    <!--Bootstrap Link css-->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <!--Google Fonts-->
    <link href='https://fonts.googleapis.com/css?family=Poppins' rel='stylesheet'>
    <!--Font awesome link-->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css">
</head>
<body style="background-color: wheat;">
    <div class="container mt-3">
        <h1 class="text-center">INSERT SHOE PRODUCT</h1>
        <form style="text-transform:none;" method="POST" enctype="multipart/form-data">

        <!--Title of product-->
            <div class="form-outline mb-4 w-50 m-auto">
                <label for="shoe_name" class="form-label">Shoe Name</label>
                <input type="text" name="shoe_name" id="shoe_name" class="form-control" placeholder="Enter shoe name" autocomplete="off" required="required">
            </div>

            <!--Product description-->
            <div class="form-outline mb-4 w-50 m-auto">
                <label for="shoe_description" class="form-label">Shoe Description</label>
                <input type="text" name="shoe_description" id="shoe_description" class="form-control" placeholder="Enter shoe description" autocomplete="off" required="required">
            </div>

             <!--Product keywords-->
             <div class="form-outline mb-4 w-50 m-auto">
                <label for="shoe_keywords" class="form-label">Shoe Keywords</label>
                <input type="text" name="shoe_keywords" id="shoe_keywords" class="form-control" placeholder="Enter shoe keywords" autocomplete="off" required="required">
            </div>
 

            <!--Shoe category-->
            <div class="form-outline mb-4 w-50 m-auto">
              <select class="form-select" id="" name="shoe_category">
                <option value="">Please choose category here</option>

                <?php
                
                    $select_query = "Select * from `categories`";
                    $result_query = mysqli_query($conn,$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>

            <!--Shoe brand-->
            <div class="form-outline mb-4 w-50 m-auto">
              <select class="form-select" id="" name="shoe_brand">
                <option value="">Please choose brand here</option>

                <?php
                
                    $select_query = "Select * from `brands`";
                    $result_query = mysqli_query($conn,$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>

          
           
            
                    

            <!--Shoe image1-->
             <div class="form-outline mb-4 w-50 m-auto">
                <label for="shoe_image1" class="form-label">Shoe image 1</label>
                <input type="file" name="shoe_image1" class="form-control" autocomplete="off" required="required">
            </div>

            <!--Shoe image2-->
            <div class="form-outline mb-4 w-50 m-auto">
                <label for="shoe_image2" class="form-label">Shoe image 2</label>
                <input type="file" name="shoe_image2" class="form-control" autocomplete="off" required="required">
            </div>

            <!--Shoe image1-->
            <div class="form-outline mb-4 w-50 m-auto">
                <label for="shoe_image3" class="form-label">Shoe image 3</label>
                <input type="file" name="shoe_image3" class="form-control" autocomplete="off" required="required">
            </div>

            <!-- Shoe Price-->
            <div class="form-outline mb-4 w-50 m-auto">
                <label for="shoe_price" class="form-label">Shoe Price (PHP)</label>
                <input type="text" name="shoe_price" id="shoe_price" class="form-control" placeholder="Enter shoe price in peso" autocomplete="off" required="required">
            </div>
            
            
            <!--CHECK BOX-->
            <div class="form-outline mb-4 w-50 m-auto">       
              
                    <label for="shoe_price" class="form-label">Select Sizes to be available</p>
               <form action="" method="post" enctype="multipart/form-data">
                
                 <label class="checkbox-inline m-1" name="shoesizes[]">
                 <input type="checkbox" value="34">34
                 </label>

                 <label class="checkbox-inline m-1" name="shoesizes[]">
                 <input type="checkbox" value="35">35
                 </label>

                 <label class="checkbox-inline m-1" name="shoesizes[]">
                 <input type="checkbox" value="36">36
                 </label>

                 <label class="checkbox-inline m-1" name="shoesizes[]">
                 <input type="checkbox" value="37">37
                 </label>

                 <label class="checkbox-inline m-1" name="shoesizes[]">
                 <input type="checkbox" value="38">38
                 </label>

                 <label class="checkbox-inline m-1" name="shoesizes[]">
                 <input type="checkbox" value="39">39 
                 </label>

                 <label class="checkbox-inline m-1" name="shoesizes[]">
                 <input type="checkbox" value="40">40
                 </label>

                 <label class="checkbox-inline m-1" name="shoesizes[]">
                 <input type="checkbox" value="41">41
                 </label>

                 <label class="checkbox-inline m-1" name="shoesizes[]">
                 <input type="checkbox" value="42">42
                 </label>

                 <label class="checkbox-inline m-1" name="shoesizes[]">
                 <input type="checkbox" value="43">43
                 </label>

                 <label class="checkbox-inline m-1" name="shoesizes[]">
                 <input type="checkbox" value="44">44
                 </label>

                    </label>
               </form>
              </div> 
            </div>

            <!--Submit Product-->
            <div class="form-outline mb-4 w-50 m-auto">
                <input type="submit" name="insert_product" class="ctn" value="Insert Product">
            </div>
            
        </form>
    </div>
</body>
</html>
Editor is loading...