Jump to content

multiple input type selects


Kano

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.