I have a set of HTML input elements which will be called iteratively by a PHP file so that their values can be submitted to a database. At design-time, I do not currently know how many versions of the element there will be.
I have an HTML/JavaScript form, where the number of rows in a table can be altered. When reading the table, I want to read all values from the elements stored in one of the rows, and use them to create an SQL query. I would then iterate this process so that there is a query for each row.
All the HTML elements are labeled to finish with the row number, which I would use to tell the process which element is required. The issue I'm finding is that when I try to do this, I get a blank value.
To add some context, here is my code:
JavaScript (A snippet from a smaller second table following the same process) Example:
var indexAdd = 1;
function addRow(){
var table = document.getElementById("addExtDet");
var row2=table.insertRow(table.rows.length);
var cell7=row2.insertCell(0);
cell7.innerHTML = indexAdd;
var cell8=row2.insertCell(1);
var t8=document.createElement("input");
t8.id = "addGrpInfo:"+indexAdd;
t8.className = "tablebox";
cell8.appendChild(t8);
var cell9=row2.insertCell(2);
var t9=document.createElement("input");
t9.id = "addGrpBus:"+indexAdd;
t9.className = "tablebox";
cell9.appendChild(t9);
indexAdd++;
}
PHP:
//Add the groups specified by the user. This while loop iterates for each group added.
$query = "";
$grpCount = $_POST['numGrps']; //This is a hidden value in the HTML code which gives the number of rows.
for($i=1; i<=$grpCount; $i++) {
$grpNum = $_POST['addGrpNum:'.$i];
$grpTime = $_POST['addGrpTime:'.$i];
$grpLoc = $_POST['addGrpLoc:'.$i];
$grpLead1 = $_POST['addGrpLead1:'.$i];
$grpLead2 = $_POST['addGrpLead2:'.$i];
$grpSpace = $_POST['addGrpSpc:'.$i];
$grpInfo = $_POST['addGrpInfo:'.$i];
$grpBus = $_POST['addGrpBus:'.$i];
//Example, the variable '$grpTime' appears to be empty/blank.
echo $grpTime;
$query = //Where each 'Insert Into Table' query will be added.
}