Note that there are some explanatory texts on larger screens.

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

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload