Kano Posted March 2, 2007 Share Posted March 2, 2007 Hi all, My prob is that i have a form for employees to input stock quantitys. Each stock has a drop down select menu for the quantity to update. Each select has a name = addqty$cnt ($cnt being the number in the loop that lists the stock followed by the drop down menu). Now, when I go to update the database and call the $addqty$cnt it does not like it? can anyone help please. thanks. Quote Link to comment https://forums.phpfreaks.com/topic/40840-multiple-input-type-selects/ Share on other sites More sharing options...
pocobueno1388 Posted March 2, 2007 Share Posted March 2, 2007 Could you post your code? Quote Link to comment https://forums.phpfreaks.com/topic/40840-multiple-input-type-selects/#findComment-197731 Share on other sites More sharing options...
mbtaylor Posted March 2, 2007 Share Posted March 2, 2007 Try this: ${"addqty$cnt"} If thats what I think you are meaning. You are wanting to create dynamic variable name, right? Quote Link to comment https://forums.phpfreaks.com/topic/40840-multiple-input-type-selects/#findComment-197732 Share on other sites More sharing options...
Kano Posted March 2, 2007 Author Share Posted March 2, 2007 Hi there, Here is the code I have been putting together this morning and its driving me round the bend (2 files -php and inc): update_stockqty_ck.php <?php if(@$_GET['update_stockqty'] == "yes") { for($cnt = 0;$cnt<$getstock_cnt;$cnt++) { if(!ereg("^[0-9]{1,4}$", ${"addqty$cnt"})) { unset($_GET['update_stockqty']); $ErrMsg = "$addqty$cnt is not a valid amount to add!"; include("update_stock.inc"); exit(); } } for($cnt = 0;$cnt<$getstock_cnt;$cnt++) { if(!ereg("^[0-9]{1,4}$", ${"subqty$cnt"})) { unset($_GET['update_stockqty']); $ErrMsg = "$subqty$cnt is not a valid amount to subtract!"; include("update_stock.inc"); exit(); } } $dbusername = ""; $hostserver = "localhost"; $dbpass = ""; $db = "db_mosley_trading"; $makeconn = mysql_connect($hostserver, $dbusername, $dbpass) or die ("Could not connect to server."); $conndb = mysql_select_db($db, $makeconn) or die ("Could not connect to database."); $update = date("Y-m-d"); for($cnt = 0;$cnt<$getstock_cnt;$cnt++) { $item_qty = $i_qty[$cnt] + ${"addqty$cnt"} - ${"subqty$cnt"}; $sqlquery_addstock = "insert into tbl_wsi (wsi_qty,wsi_lastupdated) values ('$item_qty','$update') where wsi_id = '$i_id[$cnt]'"; mysql_query($sqlquery_addstock) or die ("could not execute add stock query!"); } } else { include("update_stock.inc"); } ?> <?php $dbusername = ""; $hostserver = "localhost"; $dbpass = ""; $db = "db_mosley_trading"; $makeconn = mysql_connect($hostserver, $dbusername, $dbpass) or die ("Could not connect to server."); $conndb = mysql_select_db($db, $makeconn) or die ("Could not connect to database."); ?> <body> <form action = "update_stockqty_ck.php?update_stockqty=yes" onsubmit = "return validate_update_stockqty(this)" method = "POST"> <table> <tr> <td> <?php if(isset($ErrMsg)) { echo"<hr></td></tr><tr><td>"; $ErrMsg=stripslashes($ErrMsg); echo"$ErrMsg"; } ?> </td> </tr> <tr> <td> <hr> </td> </tr> <tr><td> <table><tr><td>Item Ref</td><td>Item Description</td><td>Stock Qty</td><td>Qty to Add</td><td>Qty to Subtract</td><td>Last Updated</td></tr> <?php $sqlquery_getstock = "select wsi_id, wsi_desc, wsi_qty from tbl_wsi"; $sqlres_getstock = mysql_query($sqlquery_getstock) or die ("Could not execute getstock query"); $getstock_cnt = 0; $i_id = ""; $i_desc = ""; $i_qty = ""; $i_lastupdated = ""; while($row_getstock = mysql_fetch_array ($sqlres_getstock)) { extract($row_getstock); $i_id[$getstock_cnt] = $wsi_id; $i_desc[$getstock_cnt] = $wsi_desc; $i_qty[$getstock_cnt] = $wsi_qty; $i_lastupdated[$getstock_cnt] = $wsi_lastupdated; $getstock_cnt++; } for($cnt=0;$cnt<$getstock_cnt;$cnt++) { echo "<tr><td>$i_id[$cnt]</td><td>$i_desc[$cnt]</td><td>$i_qty[$cnt]</td><td><select name = 'addqty$cnt'>"; for($selectcnt=0;$selectcnt<=99;$selectcnt++){ echo "<option value = '$selectcnt'"; if($selectcnt < 1) {echo "selected = 'selected'"; } echo ">$selectcnt";} echo "</select></td><td><select name = 'subqty$cnt'>"; for($selectcnt2=0;$selectcnt2<=99;$selectcnt2++){ echo "<option value = $selectcnt2>$selectcnt2";} echo "</select></td><td>$i_lastupdated[$cnt]</td></tr>"; } ?> </table></td></tr><tr><td> <input type = "submit" value = "Process" /> </td></tr></table></form></body></html> thanks. Quote Link to comment https://forums.phpfreaks.com/topic/40840-multiple-input-type-selects/#findComment-197752 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.