I'm trying to make a form that will display a product, that will allow me to type in a number of how many i want to buy, and then a submit button that sends tvs and tvno to another document. The first option with the SELECT is working, but the 2nd(my desired display of the "shop") doesnt.
<!--FORM NR 1-->
<form action="http://localhost/wordpress/restock/myDbMod/" method="post">
<table>
<caption>Sales</caption>
<tr>
<td><select name='tvs'>
<?php
foreach ($tvs as $tv) {
printf("<option value='%s'>%s inch, in stock: %s</option>
"
, $tv->getScreenSize()
, $tv->getScreenSize()
, $tv->getStockLevel());
}
?>
</select></td>
<td><input type='text' name='tvno'/></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Send"/></td>
</tr>
</table>
</form>
<!--FORM NR 2-->
<form action="http://localhost/wordpress/restock/myDbMod/" method="post">
<table>
<?php
foreach ($tvs as $tv) {
printf("<tr><td name='tvs' value='%s'>%s inch, in stock: %s</td><td><input type='text' name='tvno'/></td>
"
, $tv->getScreenSize()
, $tv->getScreenSize()
, $tv->getStockLevel());
}
?>
<td><input type="submit" value="Send"/></td></tr>
</table>
</form>
Your second form will never work.. ..and you don't need 2 separate forms either. Combine them both into 1 form as follows:
<form action="http://localhost/wordpress/restock/myDbMod/" method="post">
<table>
<caption>Sales</caption>
<tr>
<td><select name='tvs'>
<?php
foreach ($tvs as $tv) {
printf("<option value='%s'>%s inch, in stock: %s</option>
"
, $tv->getScreenSize()
, $tv->getScreenSize()
, $tv->getStockLevel());
} ?>
</select></td>
<td><input type='text' name='tvno'/></td>
</tr>
<tr>
<td>
<!-- A select box will provide better control
over 'quantity' than in input box -->
<select name='tvsno'>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Send"/></td>
</tr>
</table>
</form>
If you then want to do some processing on the figures, you need to set the form action to be a local file:
<form action="myFormProcessor.php" method="post">
The form will them submit the values:
$_POST['tvs'];
$_POST['tvsno'];
to 'myFormProcessor.php' and you can do whatever you need to from there.