I have 2 files `index.php` and `main.php` and this are the codes.
index.php
<html>
<head>
<title>Test Sync Google Sheet to SQL</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src='https://cdnjs.cloudflare.com/ajax/libs/tabletop.js/1.5.1/tabletop.min.js'></script>
<script src="js/jquery-3.2.1.min.js"></script>
</head>
<body>
<button id="myBtn">Sync Data</button>
<script>
var x = document.getElementById("myBtn");
x.addEventListener("click", init);
var publicSpreadsheetUrl = 'https://docs.google.com/spreadsheets/d/1Djso6FE61pXP1VDfyYC8_k_wnWt456hveIr-RDUW7sk/pubhtml?gid=0&single=true';
function init() {
Tabletop.init( { key: publicSpreadsheetUrl,
callback: showInfo,
simpleSheet: true } )}
function showInfo(data, tabletop) {
for (var i in data){
var trans_no = data[i];
var transno = trans_no.transno
var transdate = trans_no.transdate
var dropno = trans_no.date
var cusname = trans_no.customername
var shipto = trans_no.shipto
var active = trans_no.active
}
}
</script>
</body>
</html>
and here is main.php
<?php
include('config.php');
include('adodb/adodb.inc.php');
$db = ADONewConnection($dbdriver);
$db->Connect($dsn, $username, $password);
$transno = $_GET['transno'];
$sqlSync = 'INSERT INTO TBL_TDev (TransNo) VALUES ('.$transno.')';
$rsSync = $db->Execute($sqlSync);
?>
by clicking the button i am getting data from google sheet and pass it in variable during loop and this is the part of that.
for (var i in data){
var trans_no = data[i]; //getting e row from table
var transno = trans_no.transno
var transdate = trans_no.transdate
var dropno = trans_no.date
var cusname = trans_no.customername
var shipto = trans_no.shipto
var active = trans_no.active
//alert(transno + transdate + dropno + cusname + shipto + active);
window.location.href = "main.php?transno=" + transno;
}
}
what happens now is that the data is passed in href and go to my `main.php` to save it in sql.
My question is how can i save it using the same page? and do the saving? I mean for every data generated in the loop i will save it in sql. what happens is i can only save 1 data.
What I have tried:
I tried to use jQuery to PHP but dont know how