I am wondering if there is a way I can pass an updated PHP counting variable to an HTML form before submission. My PHP reads in a CSV file and generates an HTML table based on the number of rows in the CSV file. The counting variable then reflects the number of rows in the HTML table. Is there anyway I can update the HTML form "request f开发者_JAVA技巧orm" with the PHP variable $formvar ?
<?php
$csvFile = $_POST['myfile'];
$formvar =1;
$row = 0;
echo "<form id=\"requestform\" action=\"picklist-submit.php\" method=\"post\">";
echo "<table>";
echo "<input value=\"Submit\" type=\"submit\">";
echo "<input type=\"hidden\" name=\"formvar\" value=\"$formvar\">";
echo "<td>ISBN</td>";
echo "<td>Quantity</td>";
echo "<td>Comments</td>";
echo "<td>Initials</td>";
echo "</tr>";
if (($handle = fopen($csvFile, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
$row++;
for ($c=0; $c < $num; $c++) {
$var = $data[0];
$var2 = $data[1];
$var3 = $data[2];
$var4 = $data[3];
}
echo "<tr>";
echo "<td><input type=\"text\" name=\"upc1\" value=\"$var\"></td>";
echo "<td><input type=\"text\" name=\"quantity1\" value=\"$var2\"></td>";
echo "<td><input type=\"text\" name=\"comment1\" value=\"$var3\"></td>";
echo "<td><input type=\"text\" name=\"initials1\" value=\"$var4\"></td>";
$formvar++;
}
echo "</tr></table>";
echo "</form>";
fclose($handle);
}
?>
After echo "</tr></table>";
, add:
echo "<input type=\"hidden\" name=\"formvar\" value=\"$formvar\">";
Then when your form is submitted, you can retrieve the value from $_POST['formvar']
You can add a field outside of the loop.
$formvar++;
}
echo "<input type=\"hidden\" name=\"formvar\" value=\"".$formvar."\" />";
echo "</tr></table>";
You'll also want to remove the hidden field above the loop.
精彩评论