Hello all!
I have a problem with one of my forms which i use to save data for a warehouse management page. The user uploads an excel file which is put into the following form (see attachment) With the different buttons on the side, the user can add or delete rows. The input boxes are named row1ItemNo, row2ItemNo etc. If a new row is created after row 1 it's named as row1n1ItemNo , the following new row as row1n2ItemNo and so on. On posting of the form it is stored in a temporary file. I use the following code to fetch the data into the file:
if (IsSet($_POST['itemlist'])) {
$File = "temp/inbound_temp.txt";
$Handle = fopen($File, 'w');
$n = 1;
$x = 1;
$item = "row1itemNo";
$Data = "";
while (IsSet($_POST[$item])) {
$itemNo = "row".$n."itemNo";
$position = "row".$n."position";
$crt = "row".$n."crt";
$pcs = "row".$n."pcs";
$Data .= $_POST[$itemNo].";".$_POST[$position].";".$_POST[$crt].";".$_POST[$pcs]."\r\n";
$newitemrow="row".$n."n".$x."itemNo";
while (IsSet($_POST[$newitemrow])) {
$itemNo = "row".$n."n".$x."itemNo";
$position = "row".$n."n".$x."position";
$crt = "row".$n."n".$x."crt";
$pcs = "row".$n."n".$x."pcs";
$Data .= $_POST[$itemNo].";".$_POST[$position].";".$_POST[$crt].";".$_POST[$pcs]."\r\n";
$x++;
$newitemrow="row".$n."n".$x."itemNo";
}
$n++;
$item="row".$n."itemNo";
}
fwrite($Handle, $Data);
fclose($Handle);
}
The problem arises when rows are deleted from the form. If i.e. row 3 is deleted, the code will stop there and not read lines 4 and further. I created a workaround that counts 3 positions in advance, but abviously this doesnt work for form where many lines need to be deleted.
My question is:
- Is there a way that i can read the highest posted row value and the highest n row value (if possible per row) ?
- or do i need to change this code completely to another way of fetching the data ?
Many thanks in advance,
Lennert