title: i want ajax response only once , currently executing same queries again i want it only once after sending and geyying ajax response
body: <p>i am sending ajax req. to a php page in which i uses while loop to fetch all data , i want to reduce data by 1 and update exixting data and insert in new table , i want this operation only once but problem is that updating and inserting data more times.</p>
  
  <pre><code>    $("#create_button").click(function(){
  
               if (! confirm('Do You Want To Create Product?')) { return false;  preventDefault(); }else{
      $.ajax({
          type :'POST',
          url : 'response.php', //Here you will fetch records 
          //dataType:'json',
          data :{'select_id':select_id},
          success:function(response){
            //alert(response);
  
  
  
  
  
          }
  
      });
               }
  
   });
          }
  </code></pre>
  
  <p>in response.php</p>
  
  <pre><code>  &lt;?php
  include_once("../database/db.php");
  
  if(isset($_POST["select_id"]))
   {
      $select_id=$_POST["select_id"];
   $get_product=$con1-&gt;query("SELECT * FROM `components` WHERE 
      FIND_IN_SET($select_id,product_id)");
      $i=1;
       while($row=$get_product-&gt;fetch(PDO::FETCH_ASSOC)){
        $component_id=$row['id'];
         $component_qty=$row['quantity_remain'];
  
  
       $sql = "UPDATE components SET quantity_remain=? WHERE id=?" ;
         $con1-&gt;prepare($sql)-&gt;execute([$component_qty - 1,$component_id]);
  
  
       $i++;
          }
  
  
  
  
  
              $sql = "INSERT INTO created_products (product_id) 
   VALUES (?)";
      $con1-&gt;prepare($sql)-&gt;execute([$select_id]);    
            unset($_POST["select_id"]);
  
  
  }
  
  
  
      ?&gt;
  </code></pre>