    <?php
        require('top_inc.php');
        $categories='';
        $msg='';
        $msg1='';

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

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

            $res=mysqli_query($con, "select * from categories where categories='$categories'");
            $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="Categories already exist";   
                    }
                }
                else{
                    $msg="Categories already exist";
                }
            }
            if($msg==''){
                if (isset($_GET['id']) && $_GET['id']!='') {
                    mysqli_query($con,"update categories set categories='$categories' where id='$id'");
                }
                else{
                    mysqli_query($con,"insert into categories(categories,status) values('$categories','1')");
                }
                $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 Categories</h3>
                    <ul>
                        <li>
                            <a href="index.php">Home</a>
                        </li>
                        <li>Add Categories</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 Categories</h3>
                            </div>
                        </div>
                        <form method="post" class="mg-b-20">
                            <div class="row gutters-8">
                                <div class="col-3-xxxl col-xl-9 col-lg-9 col-12 form-group">
                                    <input type="text" placeholder="Enter Categories name ..." class="form-control" name="categories" value="<?php echo $categories; ?>">
                                </div>
                                <div class="col-1-xxxl col-xl-2 col-lg-3 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');
                ?>