title: Insert and update in one form
body: <p>yesterday my question regarding insert and update in one form i did but data are inserted and when i am clicking on edit link which is available on displayp.php it display all data's in field but when i am update any data and click on submit button its not update but it insert data next time in database and i am getting multiple record in database. Actually I had put insert and update in if condition when i am updating its not moving in else part so please help me... Thank You..</p>
  
  <pre><code>&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'])=='POST')
     {
  
     echo "working"; 
     $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="post" 
           enctype="multipart/form-data"  name="myform" &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 if(isset($query4['prodnm'])){echo $query4['prodnm'];}?&gt;"/&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;        
                 &lt;textarea class="form-control" id="catdtl" 
                    name="prod_dtl" placeholder="Product Detail"  
                    "rows="10" cols="62" required&gt;
                 &lt;?php if(isset($query4['prod_dtl'])){
                    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 if(isset($query4['pdf'])){
                    echo $query4['pdf'];} ?&gt;                        
              &lt;/div&gt;
              &lt;div class="checkbox"&gt;
                 &lt;label&gt;
                 &lt;input id="checkbox" type="checkbox" name="updates" required 
                    &lt;?php  if(isset($query4['downld'])) 
                       { if($query4['downld'] == 'Yes') 
                       echo "checked='checked'"; echo $query4['downld'];} 
                                   ?&gt; /&gt;
                 Is Downloadable &lt;br /&gt;
                 &lt;/label&gt;
              &lt;/div&gt;
              &lt;input type="text"  
                 placeholder="Date of Upload" id="datepicker-7" 
                 name="date"  value="&lt;?php if(isset($query4['date'])){
                    echo $query4['date'];}?&gt;" 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;/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>