EchoFool Posted February 15, 2008 Share Posted February 15, 2008 Not sure if I am doing this correctly so before i write my entire script thought I'd have some professionals on this site take a look tell me if I am doing this correctly? I have tried to create an array in a form to process on the next page but am getting problems with it. I have two entires the user has to do which is "select the items" and set the "quantity" of those items.. So lets say: ItemID |Quantity 3 4 2 2 7 1 These are the items the user picked and the corresponding quantities. Now i have applied that to my form below: <?php $Array = 0; While($row = mysql_fetch_assoc($GetItems)){ $ItemID = $row['ItemID']; $Quantity = $row['Quantity']; $Get = mysql_query("SELECT Name,Type FROM item WHERE ItemID='$ItemID' AND Trade='1'") Or die(mysql_error()); $row = mysql_fetch_assoc($Get); $Name = $row['Name']; $Type = $row['Type']; $Array++; ?> <tr> <td width="200" align="center" class="blackBold"><?=$Name?></td> <td width="200" align="center" class="blackBold"><?=$Quantity?></td> <td width="200" align="center" class="blackBold"><input type="text" size="16" name="Quantity[<?=$Array?>]" value=""></td> <td width="200" align="center" class="blackBold"><input type="checkbox" name="Checkbox[<?=$Array?>]" value="<?=$ItemID?>"></td> </tr> <?php } ?> This part is fine but the below part is my process page which i need help with i get an undefined error... to do with $ItemID (you can tell im a noob with arrays). Notice: Undefined variable: ItemID in C:\xampp\htdocs\transferprocess.php on line 5 This is my process: <?php If(isset($_POST['Button1']) && isset($_POST['Checkbox']) && isset($_POST['Quantity'])){ for($Array = 0; $Array < count($ItemID); $Array++){ if($Quantity[$Array]){ echo $ItemID[$Array] . " - " . $Quantity[$Array]; }else{ echo "Please insert a quantity for item id " . $item[$a]; } } } ?> It's so confusing! Not sure if I am going in the right direction? Am i ? Link to comment https://forums.phpfreaks.com/topic/91334-form-array-help/ Share on other sites More sharing options...
EchoFool Posted February 15, 2008 Author Share Posted February 15, 2008 bump Link to comment https://forums.phpfreaks.com/topic/91334-form-array-help/#findComment-468081 Share on other sites More sharing options...
sasa Posted February 16, 2008 Share Posted February 16, 2008 Notice: Undefined variable: ItemID in C:\xampp\htdocs\transferprocess.php on line 5 you must set up your variable $ItemID and $Quantity $ItemID=$_POST['Checkbox']; $Quantity=$_POST['Quantity']; use foreach loop Link to comment https://forums.phpfreaks.com/topic/91334-form-array-help/#findComment-468114 Share on other sites More sharing options...
EchoFool Posted February 16, 2008 Author Share Posted February 16, 2008 So like this: <?php for($Array = 0; $Array < count($_POST['Checkbox']; $Array++){ $ItemID=$_POST['Checkbox']; $Quantity=$_POST['Quantity']; } ?> Some thing like that? Link to comment https://forums.phpfreaks.com/topic/91334-form-array-help/#findComment-468330 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.