Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
how to insert data to gsheet with each item

Hi i am inserting data multiple data with for loop . and fetching thos data from database nd inserting to ghseet again now i want to make it happen at a time.

my for each loop is here

if (in_array($_POST['prodname'][$key], $checked_array)) {
                    $prodname = $_POST['prodname'][$key];
                    $prod_price = $_POST['prod_price'][$key];
                    $prod_qty = $_POST['prod_qty'][$key];
                    $prodsname = $_POST['prodsname'][$key];
                    $app_id = $_POST['app_id'][$key];
                    $district = $_POST['district'][$key];
                    $upazilla = $_POST['upazilla'][$key];
                    $store_name = $_POST['StoreName'][$key];
                    $ward = $_POST['ward'][$key];






                    for ($x = 0; $x < $prod_qty; $x++) {

                        $couponnumber =  random_int(100, 100000);

                        $sql = "INSERT INTO `retailer_sales`( `product`, `Amount`, `quantity`,`C_Number`,`Retailer_Number`,`Dtistrict`,`Upzilla`,`coupon_number`,`StoreName`,`ward`) VALUES ('$prodname','$prod_price','$prod_qty','$prodsname','$app_id','$district','$upazilla','$couponnumber','$store_name','$ward')";

                        $result  = $db->query($sql);

                        if ($result) {


                          $_SESSION["status"] = true;
                        } else {
                          $_SESSION["server_down"] = true;
                          echo '<script>window.location="../../pages/product_sale/main.php";</script>';
                        }
                    }
                }


and my javascript code for sending to gsheet is


<script>
  const scriptURL = 'https://script.google.com/macros/s/AKfycbzfMQmBwDEO8k0H8jeLlKTE_GzK0XuQ1unZd_5ib_DDBhM17b6FVahIW5f3W4FyfCNOAw/exec'
  const form = document.forms['submit-to-gateway']

  form.addEventListener('submit', e => {
    e.preventDefault()
    fetch(scriptURL, {
        method: 'POST',
        body: new FormData(form)
      })
      .then(response => $("#form_alerts").html("<div class='alert alert-success'>Id Sent Successfully.</div>"))
      .catch(error => $("#form_alerts").html("<div class='alert alert-danger'>Id Could not be Sent.</div>"))
      $('#myForm')[0].reset();
  })
</script>

i want to insert each data which is inserting to mysql database. help me with this.

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!