    <?php
        require('top_inc.php');
        $name='';
        $image='';
        $digi='';
        $description='';


        $msg='';
        $msg1='';
        $image_required='required';

        if (isset($_GET['id']) && $_GET['id']!='') {
            $image_required='';
            $id=get_safe_value($con,$_GET['id']);
            $res=mysqli_query($con, "select * from testimonial where id='$id'");
            $check=mysqli_num_rows($res);
            if($check>0){
                $row=mysqli_fetch_assoc($res);
                $name=$row['name'];
                $digi=$row['digi'];
                $description=$row['description'];
            }
            else{
            }
        }

        if(isset($_POST['submit'])){
            $name=get_safe_value($con,$_POST['name']);
            $digi=get_safe_value($con,$_POST['digi']);
            $description=get_safe_value($con,$_POST['description']);

            $res=mysqli_query($con, "select * from testimonial where name='$name'");
            $check=mysqli_num_rows($res);
            if($check>0){
                if (isset($_GET['id']) && $_GET['id']!='') {
                    $getData=mysqli_fetch_assoc($res);
                    if($id==$getData['id']){

                    }
                    else{
                        $msg="Products already exist";   
                    }
                }
                else{
                    $msg="Products already exist";
                }
            }
            if($_FILES['image']['type']!='image/png' && $_FILES['image']['type']!='image/jpg' && $_FILES['image']['type']!='image/jpeg'){
                $msg="Please select only png, jpg and jpeg image formate";
            }
            if($msg==''){
                if (isset($_GET['id']) && $_GET['id']!='') {
                    if ($_FILES['image']['name']!='') {
                        $image=rand(111111111,999999999).'_'.$_FILES['image']['name'];
                        move_uploaded_file($_FILES['image']['tmp_name'], PRODUCT_IMAGE_SERVER_PATH.$image);
                        $update_sql="update testimonial set name='$name',digi='$digi',description='$description',image='$image' where id='$id'";
                    }
                    else{
                        $update_sql="update testimonial set name='$name',digi='$digi',description='$description' where id='$id'";
                    }
                    mysqli_query($con,$update_sql);
                }
                else{
                    $image=rand(111111111,999999999).'_'.$_FILES['image']['name'];
                    move_uploaded_file($_FILES['image']['tmp_name'], PRODUCT_IMAGE_SERVER_PATH.$image);
                    mysqli_query($con,"insert into testimonial(name,digi,description,image) values('$name','$digi','$description','$image')");
                }
                $msg1="Categories successfull submit";
                
            }

        }
        
    ?>
        <!-- Page Area Start Here -->
        <div class="dashboard-page-one">
            <!-- Sidebar Area Start Here -->
            <?php
                require('side_menu.php');
            ?>
            <!-- Sidebar Area End Here -->
            <div class="dashboard-content-one">
                <!-- Breadcubs Area Start Here -->
                <div class="breadcrumbs-area">
                    <h3>Add Testimonial</h3>
                    <ul>
                        <li>
                            <a href="index.php">Home</a>
                        </li>
                        <li>Add Testimonial</li>
                    </ul>
                </div>
                <!-- Breadcubs Area End Here -->
                <!-- Student Table Area Start Here -->
                <div class="card height-auto">
                    <div class="card-body">
                        <div class="heading-layout1">
                            <div class="item-title">
                                <h3>Add Testimonial</h3>
                            </div>
                        </div>
                        <form method="post" enctype="multipart/form-data" class="mg-b-20">
                            <div class="row gutters-8">
                                <div class="col-3-xxxl col-xl-6 col-lg-6 col-12 form-group">
                                    <input type="text" placeholder="Enter Product name ..." class="form-control" name="name" value="<?php echo $name; ?>">
                                </div>
                                <div class="col-3-xxxl col-xl-6 col-lg-6 col-12 form-group">
                                    <input type="text" placeholder="Enter Designation ..." class="form-control" name="digi" value="<?php echo $digi; ?>">
                                </div>
                                <div class="col-3-xxxl col-xl-12 col-lg-12 col-12 form-group">
                                    <input type="file" class="form-control" name="image" <?php echo $image_required ?>>
                                </div>
                                <div class="col-3-xxxl col-xl-12 col-lg-12 col-12 form-group">
                                    <textarea placeholder="Enter Product Short description ..." class="form-control" name="description"><?php echo $description; ?></textarea>
                                </div>

                                <div class="col-1-xxxl col-xl-12 col-lg-12 col-12 form-group">
                                    <button type="submit" name="submit" class="fw-btn-fill btn-gradient-yellow">SUBMIT</button>
                                </div>
                            </div>
                        </form>
                        <div class="field_error">
                            <?php echo $msg ?>
                        </div>
                        <div class="field_error">
                            <?php echo $msg1 ?>
                        </div>
                    </div>
                </div>
                <!-- Student Table Area End Here -->
                <?php
                    require('footer_inc.php');
                ?>