I have a while loop creating a form, what I'm wanting the user to do is input a number next to the items they want, upon submitting it would submit both the number they have entered plus a variable I provide (without them seeing the variable). Is this possible? The php is looping through text files, outputting each line as an option for the user.
while(($line = fgets($filehandle)) !== false){
$itemParts = explode(" - ",$line);
$item = $itemParts[0];
$price = $itemParts[1];
echo "<input type='text' name='hardware[]' value='{$item}-|-{$price}'>£".$price." ".$item."<br />";
}
On the resulting page I am looping through the hardware[] array to display to the user their choices as well as updating a database.
foreach ($_POST['hardware'] as $itemWanted){
$itemParts = explode('-|-',$itemWanted);
$item = $itemParts[0];
$cost = $itemParts[1];
echo $item.' £'.$cost.'<br />';
$total += $cost;
$allHardware .= "**".$item." - GBP ".$cost;
}
I'm probably going about it the wrong way, but does anyone know if this is possible with an unknown number of text files and items? My current way of working is that there is a checkbox instead of the textbox and it all works OK, but now I need the users to choose an amount they require.
while(($line = fgets($filehandle)) !== false){
$itemParts = explode(" - ",$line);
$item = $itemParts[0];
$price = $itemParts[1];
echo "<input type='checkbox' name='hardware[]' value='{$item}-|-{$price}'><font size='2'>£".$price." ".$item."</font><br />";
}
Thanks in advance for any help