title: insert and update in one form in php
body: <p><strong>How to Insert and update  using one form in php. Insert and Update not working 
  what to do. I have file productinsert.php and one file for display data displayProduct.php when i am inserting data are not inserted and it redirect on same page it not displaying data on addProduct.php also not updating plz help</strong></p>
  
  <pre><code> &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 
  1.0 Transitional//EN"         
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
  &lt;title&gt;Untitled Document&lt;/title&gt;
  &lt;?php
  include('header1.php');
  ?&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;?php
  include('sidenav.php');
  ?&gt;
  
  
  
  
  &lt;div id="page-wrapper" &gt;
   &lt;div id="page-inner"&gt;
   &lt;div class="row"&gt;
   &lt;div class="col-md-12"&gt;
   &lt;h2&gt;Add Product&lt;/h2&gt;   
  
  
  
  &lt;/div&gt;
          &lt;/div&gt;
           &lt;!-- /. ROW  --&gt;
           &lt;hr /&gt;
           &lt;div class="row"&gt; 
  
                    &lt;?php 
  
                                  include('config.php');
                    if($_SERVER['REQUEST_METHOD']=='POST')
                    {
                          if(isset($_POST['submit']))
                              {
  
  
                                  $fileName=$_FILES["filepdf"]["name"];
                                  $fileSize=$_FILES["filepdf"]["size"]/2024;
                                  $fileType=$_FILES["filepdf"]["type"];   
                                  $fileTmpName=$_FILES["filepdf"]["tmp_name"];  
  
                                  if($fileType=="application/pdf"){
                                  if($fileSize&lt;=200){
  
                          //New file name
                                  $random=rand(1111,9999);
                                  $newFileName=$random.$fileName;
  
                          //File upload path
                                  $uploadPath="testUpload/".$newFileName;
  
                          //function for upload file
  
                              if(move_uploaded_file($fileTmpName,$uploadPath))
                              {
                                  echo "Successful&lt;BR&gt;"; 
                                  echo "File Name :".$newFileName."&lt;BR&gt;"; 
                                  echo "File Size :".$fileSize." kb"."&lt;BR&gt;"; 
                                  echo "File Type :".$fileType."&lt;BR&gt;"; 
                               }
                              else
                              {
  
  
  echo "Maximum upload file size limit is 200 kb";
                              }
                          }
                              else
                              {
                                          return false;
  
  
  echo "You can only upload a pdf doc file.";
                               }  
  
  
                                      echo "here downld";
  
  
  $updates = isset($_POST['updates']) ? 'Yes' : 'No';
  
                                      $catnm=$_POST['catnm'];
                                      $prodnm=$_POST['prodnm'];
                                      $prod_dtl=$_POST['prod_dtl'];
  
                                      //$updates=$_POST['downld'];
                                      $date=$_POST['date'];
  
  
  
  $query=("insert into addproduct(catnm,prodnm,prod_dtl,pdf,downld,date)
  
  
  values('$catnm','$prodnm','$prod_dtl','$uploadPath','$updates','$date')");
                                      $result = mysql_query($query,$conn);
                                      echo"record inserted";
                                      if($result)
                                      {
                                          header("location:addProduct.php");
                                      }
                                  }
  
                          }
                    }
                    else if($_SERVER['REQUEST_METHOD']=='GET')
                    {
                      if(isset($_GET['id']))
                      {
                          $id = $_GET['id'];
                          if(isset($_POST['submit']))
                          {
  
  
  
  $updates['downld'] = isset($_POST['downld']) ? 'Yes' : 'No';
                                  $cat['catnm']=$_POST['catnm'];
                                  $prodnm['prodnm']=$_POST['prodnm'];
                                  $prod_dtl['prod_dtl']=$_GET['prod_dtl'];
                                  $pdf['pdf']=$_GET['pdf'];
                                  $downld['downld']=$_GET['downld'];
                                  $date['date']=$_GET['date'];
  
  
  
  $query3=mysql_query("update addproduct set catnm='$cat',            
                                  prodnm='$prodnm',prod_dtl='$prod_dtl'
  
  
  ,pdf='$pdf',downld='$updates',date='$date' where id='$id'");
  
                                  if($query3)
                                  {
                                      header('location:addProduct.php');
                                  }
                           }
  
  
  $query1=mysql_query("select * from addproduct where id='$id'");
                          $query4=mysql_fetch_array($query1);
                          //echo "&lt;pre&gt;";
                          //print_r($query4);
                      }
                      }
                    ?&gt;
  
         &lt;div class="col-md-6 col-sm-12 col-xs-12"&gt;      
                  &lt;div class="panel-body"&gt;            
  
  
  &lt;form role="form"  method="get" enctype="multipart/form-data"   
  
  name="myform"  action= "&lt;?php echo $_SERVER['PHP_SELF'];?&gt;"&gt;
                  &lt;br/&gt;
  
                  &lt;label&gt;Select Category:&lt;/label&gt;      
                  &lt;div class="form-group"&gt;
                    &lt;?php
  
                          include('config.php');
  
  
  $query1=mysql_query("select catnm from addcategory");
                          ?&gt;
  
  
  &lt;select class=form-control m-b-10 name=catnm id=catnm &gt;
                          &lt;?php
                           echo"&lt;option&gt;---Select---&lt;/option required&gt;";
                          while($query=mysql_fetch_array($query1))
                          {
  
                              $selectedCat = '';
                              if($query[catnm] == $query4['catnm'])
                              {
                                  $selectedCat = "selected";
                              }
  
  
  
   echo "&lt;option value='$query[catnm]' $selectedCat &gt;$query[catnm]&lt;/option&gt;"; 
                              }
  
                      ?&gt;                                    
                      &lt;/select&gt;
  
  
  
              &lt;br/&gt;                 
             &lt;div class="form-group"&gt; 
  
  
  &lt;input type="text" class="form-control" id="prodnm" 
    placeholder="Product Name" name="prodnm" required 
                 value= "&lt;?php $query4['prodnm']; ?&gt;"/&gt;
             &lt;/div&gt;
  
           &lt;div class="form-group"&gt;       
  
  
   &lt;textarea   class="form-control" id="catdtl" name="catdtl" 
  
  placeholder="Product Detail"  "rows="10" cols="62" required&gt;
               &lt;?php echo $query4['prod_dtl']; ?&gt;
          &lt;/textarea&gt;
          &lt;/div&gt;        
          &lt;div class="form-group"&gt;
          &lt;label for="exampleInputFile"&gt;PDF File&lt;/label&gt;
  
  
  
  
   &lt;input type="file" 
  id="exampleInputFile" accept="application/pdf" name="filepdf" required &gt;
  
  
          file : &lt;?php echo $query4['pdf']; ?&gt;                        
          &lt;/div&gt;
  
          &lt;div class="checkbox"&gt;
          &lt;label&gt;
          &lt;input id="checkbox" type="checkbox" name="updates" required 
  </code></pre>
  
   
  
  <pre><code> /&gt; Is Downloadable &lt;br /&gt;
              &lt;/label&gt;
              &lt;/div&gt;
  
  
  
  
  
  
  
  
  
  &lt;input type="text"  
  placeholder="Date of Upload" id="" name="date" required /&gt;
           &lt;div style="padding-top:20px;padding-bottom:40px;width:650px;"&gt;
           &lt;input type="submit" name="submit" id="button" tabindex="2"/&gt;
  
  
           &lt;hr/&gt;
  
           &lt;/form&gt;
  
                  &lt;?php
                          if(isset($_GET['id']))
                          {   
  
                                  $id=$_GET['id'];
                              if(isset($_POST['submit']))
                              {
  
  
  
  $updates['downld'] = isset($_POST['downld']) ? 'Yes' : 'No';
                                      $cat['catnm']=$_POST['catnm'];
                                      $prodnm['prodnm']=$_POST['prodnm'];
                                      $prod_dtl['prod_dtl']=$_GET['prod_dtl'];
                                      $pdf['pdf']=$_GET['pdf'];
                                      $downld['downld']=$_GET['downld'];
                                      $date['date']=$_GET['date'];
  
  
  
  $query3=mysql_query("update addproduct set catnm='$cat',            
  prodnm='$prodnm',prod_dtl='$prod_dtl'
  ,pdf='$pdf',downld='$updates',date='$date' where id='$id'");
  
                                      if($query3)
                                      {
                                          header('location:addProduct.php');
                                      }
                               }
  
  
  
                          }
  
  
                                      ?&gt;
  
   &lt;/div&gt;
                   &lt;!-- /. ROW  --&gt;
      &lt;/div&gt;
               &lt;!-- /. PAGE INNER  --&gt;
              &lt;/div&gt;
           &lt;!-- /. PAGE WRAPPER  --&gt;
          &lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>