I have a simple DB and a small table in it. This table named STOCK has only one column – names of different items in a stationery.
I am dynamically generating a form in PHP-MySQL which fetches Item from STOCK (such as Pencil, Pen etc.) and displays them by using echo() function. So I have generated a form which displays Item and correspondingly an <input> text box. Upon submitting this form, how can I access all the Names and their text inputs by traversing through the $_GET array?
The dynamically generated form is:
$res = mysql_query("SELECT * FROM Stock");
echo "<form name='input' action='add_stock_later.php' method='get'>";
echo "<table align='left' border='1'>
<tr>
<th>Item</th>
<th>Quantity</th>
<th>Remarks</>
</tr>";
while($row = mysql_fetch_array($res))
{
$item = $row['Item'];
echo "<tr>";
echo "<td>" . $item . "</td>";
echo "<td><input type='text' name='$item'></td>";
echo "<td><input type='text' name='Remarks'></td>";
echo "</tr>";
}
echo "<tr><td></td>
<td align='middle'><input type='submit' value='Submit'></td></tr>";
echo "</table>";
Now in the add_stock_later.php, how can I access all these $item and it’s corresponding input without having to manually do it using $_GET['Pencil'], $_GET['Pen'] and so on.
First edit your form.
Then use
foreach().