<?php
session_start();
include('conn.php');
if(isset($_POST['submit']))
{
  
  $name=$_POST['add_name'];
  $add_about=$_POST['add_about'];
   
  $category=$_POST['category'];
  
// $vendor=$_SESSION['code'];

  
  //$sub=$_POST['status'];

  $image_name1=$_FILES['file1']['name'];                  /* Update a image 2*/
$image_size=$_FILES['file1']['size'];
$image_type=$_FILES['file1']['type'];
$image_tmp=$_FILES['file1']['tmp_name'];
$store="pic/".$image_name1;                               /* location to store image 2 */
$upload=move_uploaded_file($image_tmp,$store);
    
    if($image_name1=='')
    {
     $image_name1=$_POST['hidden1'];
    }
      else
      {
      $image_name1=$_FILES['file1']['name'];
    }


$query=mysqli_query ($conn,"UPDATE add_adver SET product_name='$name',product_price='$add_about',cate_id='$category',product_img='$image_name1',date=now() where id='".$_GET['change']."'");
if($query==true)
{
  echo"<script>alert('Your details has been updated');
  window.location.href='adver-list.php';</script>";
}
else
{
  echo"<script>alert('Your details has not been updated');window.location.href='adver-list.php';</script>";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>AdminLTE 3 | General Form Elements</title>

  <!-- Google Font: Source Sans Pro -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="plugins/fontawesome-free/css/all.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="dist/css/adminlte.min.css">
  <script async src="https://www.googletagmanager.com/gtag/js?id=UA-90614514-2"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-90614514-2');
</script>
<meta name="google-site-verification" content="Htm2ZwE8DZTCNr7vy9OKPmcHlBy7_bkVi43Td4dpxvQ" />    <!--    Google Analytics Code Ends-->


 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  
  <script src="js/countrystatecity.js?v2"></script>

</head>
<body class="hold-transition sidebar-mini">
<div class="wrapper">
  <!-- Navbar -->
  <?php
 include "header.php"; 
  ?>
  <!-- /.navbar -->
  <?php
 include "sidebar.php"; 
  ?>

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1>Add Advertisment</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="#">Home</a></li>
              <li class="breadcrumb-item active">Update  Advertisment</li>
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
         <div class="row">
          <!-- left column -->
          <div class="col-md-12">
            <!-- general form elements -->
            <div class="card card-primary">
              <div class="card-header">
                <h3 class="card-title">Update  Advertisment</h3>
              </div>
              <!-- /.card-header -->
              <!-- form start -->
              <?php $query=mysqli_query($conn,"SELECT * FROM  add_adver where id='".$_GET['change']."'"  );
            $row=mysqli_fetch_array($query);
 
 ?>
              <form method="post" enctype="multipart/form-data">
                <div class="card-body">
                  <div class="form-group">
                    <label for="exampleInputEmail1">Advertisment Name</label>
                    <input type="text" value="<?php echo $row['product_name'];?>" class="form-control" name="add_name" id="exampleInputEmail1" placeholder="">
                  </div>
                  <div class="form-group">
                    <label for="exampleInputPassword1">About  Advertisment</label>
                    <input type="text" value="<?php echo $row['product_price'];?>" class="form-control" name ="add_about"id="exampleInputPassword1" placeholder="">
                  </div>
               
                  
                 
                
                  <div class="form-group ca-sh-user">
                  <label for="exampleInputPassword1">Select Category</label>
  <?php 
                 
                  $nitin=mysqli_query($conn,"SELECT * FROM add_category  order by cate_id");
                  ?>
             <select class="form-control"   name="category">
                    <?php while($sql=mysqli_fetch_array($nitin)){?>
                    <option value="<?php echo $sql['category_name'];?>" <?php if($sql['category_name']==$row['cate_id']) { echo "selected"; }?> ><?php echo $sql['category_name'];?></option>
                  <?php }?>
                    </select>
                            </div>

     
                            
                            
                            <div class="col-md-12">
          <i class="fas fa-lock prefix grey-text"></i>
      <label data-error="wrong" data-success="right" for="defaultForm-pass">Image1 </label>
          <input type="file" name="file1" id="defaultForm-pass" class="form-control validate" >
      <input type="hidden" name="hidden1" class="form-control" value="<?php echo $row['add_img'];?>" >
           <center> <img src="pic/<?php echo $row['product_img']; ?>" style="width:100px;height:100px;"></center>
    </div>
                            
                 
                   
                            
 
                  </div>
            
                
                <!-- /.card-body -->

                <div class="card-footer">
                  <button type="submit" name ="submit" class="btn btn-primary">Submit</button>
                </div>
              </form>
              
              </div>
              
              
           
            <!-- /.card -->

            <!-- general form elements -->
            <!-- <div class="card card-primary">
              <div class="card-header">
                <h3 class="card-title">Different Styles</h3>
              </div> -->
              <!-- /.card-header -->
              <!-- <div class="card-body">
                <h4>Input</h4>
                <div class="form-group">
                  <label for="exampleInputBorder">Bottom Border only <code>.form-control-border</code></label>
                  <input type="text" class="form-control form-control-border" id="exampleInputBorder" placeholder=".form-control-border">
                </div>
                <div class="form-group">
                  <label for="exampleInputBorderWidth2">Bottom Border only 2px Border <code>.form-control-border.border-width-2</code></label>
                  <input type="text" class="form-control form-control-border border-width-2" id="exampleInputBorderWidth2" placeholder=".form-control-border.border-width-2">
                </div>
                <div class="form-group">
                  <label for="exampleInputRounded0">Flat <code>.rounded-0</code></label>
                  <input type="text" class="form-control rounded-0" id="exampleInputRounded0" placeholder=".rounded-0">
                </div>
                <h4>Custom Select</h4>
                <div class="form-group">
                  <label for="exampleSelectBorder">Bottom Border only <code>.form-control-border</code></label>
                  <select class="custom-select form-control-border" id="exampleSelectBorder">
                    <option>Value 1</option>
                    <option>Value 2</option>
                    <option>Value 3</option>
                  </select>
                </div>
                <div class="form-group">
                  <label for="exampleSelectBorderWidth2">Bottom Border only <code>.form-control-border.border-width-2</code></label>
                  <select class="custom-select form-control-border border-width-2" id="exampleSelectBorderWidth2">
                    <option>Value 1</option>
                    <option>Value 2</option>
                    <option>Value 3</option>
                  </select>
                </div>
                <div class="form-group">
                  <label for="exampleSelectRounded0">Flat <code>.rounded-0</code></label>
                  <select class="custom-select rounded-0" id="exampleSelectRounded0">
                    <option>Value 1</option>
                    <option>Value 2</option>
                    <option>Value 3</option>
                  </select>
                </div>
              </div> -->
              <!-- /.card-body -->
            <!-- </div> -->
            <!-- /.card -->

            
              
                    
</div>
            <!-- /.card -->
          <!--/.col (right) -->
        </div>
        <!-- /.row -->
      </div><!-- /.container-fluid -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
  <?php
 include "footer.php"; 
  ?>

  <!-- Control Sidebar -->
  <aside class="control-sidebar control-sidebar-dark">
    <!-- Control sidebar content goes here -->
  </aside>
  <!-- /.control-sidebar -->
</div>
<!-- ./wrapper -->

<!-- jQuery -->
  <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script><script  src="script.js"></script>

<script src="plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- bs-custom-file-input -->
<script src="plugins/bs-custom-file-input/bs-custom-file-input.min.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="dist/js/demo.js"></script>
<!-- Page specific script -->
<script>
$(function () {
  bsCustomFileInput.init();
});

</script>
</body>
</html>
