RootChaos
02-04-2008, 12:12 PM
Hi Guys
I have been trying to read up on using HTML Form arrays to PHP, but can't seem to get this working...
I basically have a select check box next to each item with a QTY text field. I want to assocaite the product id of each select check box with the QTY text field of each row, hence, the checkbox and qty textfield should go hand-in-hand. Once the values get to my php page for processing, I need to some way associate the two fields and write the information into a mysql table like so "insert into tblname set pid = '$product id from html form', qty = '$qry associated with the pid'"
On my HTML Form page :-
--------------snip--------------------
<?
$qry_products = "SELECT * from products";
$exec_qry_products = mysql_query($qry_products) or die ("Invalid MySQL Query :" . mysql_error());
?>
<table width="955" border="0" cellspacing="2" cellpadding="2">
<tr>
<td colspan="6"><div align="left"><strong>Select from the list of available products below.</strong><br />
<br />
</div></td>
</tr>
<tr>
<td width="30"><div align="left"></div></td>
<td width="33"><div align="left"><strong>PID</strong></div></td>
<td width="106"><div align="left"><strong>Product Code</strong></div></td>
<td width="142"><div align="left"><strong>Product Name</strong></div></td>
<td width="536"><div align="left"><strong>Product Description</strong></div></td>
<td width="70"><div align="center"><strong>QTY</strong></div></td>
</tr>
<tr> <? while ($arrdetails = mysql_fetch_array($exec_qry_products)) { ?>
<td><div align="center">
<input type="checkbox" name="products[]" id="products" value="<?= $arrdetails['pid']; ?>" />
</div></td>
<td><div align="left"><?= $arrdetails['pid']; ?></div></td>
<td><div align="left"><?= $arrdetails['productcode']; ?></div></td>
<td><div align="left"><?= $arrdetails['productname']; ?></div></td>
<td><div align="left"><?= $arrdetails['productdescription']; ?></div></td>
<td><div align="center">
<input name="qty[]" type="text" id="qty" size="5" />
</div></td>
</tr> <? } ?>
</table>
<br />
<br />
<table width="955" border="0" cellspacing="2" cellpadding="2">
<tr>
<td><div align="left">
<input type="submit" name="button" id="button" value="Submit Order" />
</div></td>
</tr>
</table>
<br />
</form>
Hope it makes sense. Thanks in advance.
Regards
RC
I have been trying to read up on using HTML Form arrays to PHP, but can't seem to get this working...
I basically have a select check box next to each item with a QTY text field. I want to assocaite the product id of each select check box with the QTY text field of each row, hence, the checkbox and qty textfield should go hand-in-hand. Once the values get to my php page for processing, I need to some way associate the two fields and write the information into a mysql table like so "insert into tblname set pid = '$product id from html form', qty = '$qry associated with the pid'"
On my HTML Form page :-
--------------snip--------------------
<?
$qry_products = "SELECT * from products";
$exec_qry_products = mysql_query($qry_products) or die ("Invalid MySQL Query :" . mysql_error());
?>
<table width="955" border="0" cellspacing="2" cellpadding="2">
<tr>
<td colspan="6"><div align="left"><strong>Select from the list of available products below.</strong><br />
<br />
</div></td>
</tr>
<tr>
<td width="30"><div align="left"></div></td>
<td width="33"><div align="left"><strong>PID</strong></div></td>
<td width="106"><div align="left"><strong>Product Code</strong></div></td>
<td width="142"><div align="left"><strong>Product Name</strong></div></td>
<td width="536"><div align="left"><strong>Product Description</strong></div></td>
<td width="70"><div align="center"><strong>QTY</strong></div></td>
</tr>
<tr> <? while ($arrdetails = mysql_fetch_array($exec_qry_products)) { ?>
<td><div align="center">
<input type="checkbox" name="products[]" id="products" value="<?= $arrdetails['pid']; ?>" />
</div></td>
<td><div align="left"><?= $arrdetails['pid']; ?></div></td>
<td><div align="left"><?= $arrdetails['productcode']; ?></div></td>
<td><div align="left"><?= $arrdetails['productname']; ?></div></td>
<td><div align="left"><?= $arrdetails['productdescription']; ?></div></td>
<td><div align="center">
<input name="qty[]" type="text" id="qty" size="5" />
</div></td>
</tr> <? } ?>
</table>
<br />
<br />
<table width="955" border="0" cellspacing="2" cellpadding="2">
<tr>
<td><div align="left">
<input type="submit" name="button" id="button" value="Submit Order" />
</div></td>
</tr>
</table>
<br />
</form>
Hope it makes sense. Thanks in advance.
Regards
RC