Jump to content

Form Array Help


EchoFool

Recommended Posts

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
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.