gavin1512 Posted January 27, 2008 Share Posted January 27, 2008 Good Afternoon, I am having a slight issue in writing mulitple text box entries to the database, basically I have a shopping basket and next to each item is a textbox with the name quantity, the items are displayed using a loop to display entries from an array: foreach($_SESSION['order'] as $key => $product){ ?> <tr> <td><?php echo $_SESSION['order'][$key]['productnumber']?></td> <td><?php echo $_SESSION['order'][$key]['type']?></td> <td><?php echo $_SESSION['order'][$key]['description']?></td> <td>£<?php echo $_SESSION['order'][$key]['price']?></td> <td width="198"><input name="quantity" type="text"></td> the problem I am having is that it will only take the first entry for quantity and put that against each item and ignore the other text boxes. I am just using a simple GET statement, does the GET statement need to be put into a loop? Quote Link to comment https://forums.phpfreaks.com/topic/88054-multiple-text-box-get-statement-problem/ Share on other sites More sharing options...
Bauer418 Posted January 27, 2008 Share Posted January 27, 2008 Well, the name of the field needs to be quantity[id] here, for example: <?php foreach ($_SESSION['order'] as $key=>$product) { echo '<tr> <td>' . $product['productnumber'] . '</td> <td>' . $product['type'] . '</td> <td>' . $product['description'] . '</td> <td>£' . $product['price'] .'</td> <td width="198"><input name="quantity[' . $key . ']" type="text" /></td> </tr>'; } ?> Then your PHP script to access the fields would look like this: <?php foreach ($_GET['quantity'] as $key=>$quantity) { // $key now relates to the key of the item in that session // i.e. if $key is 4, then you are editing the quantity for $_SESSION['order'][4] } ?> Quote Link to comment https://forums.phpfreaks.com/topic/88054-multiple-text-box-get-statement-problem/#findComment-450497 Share on other sites More sharing options...
gavin1512 Posted January 27, 2008 Author Share Posted January 27, 2008 Thank you for your assistance, I have updated my form fine just having a slight problem on the script I have the foreach loop of: { $query = "insert into productorder values ('".$order."','".$_SESSION['order'][$key]['productnumber']."','".$quantity."', 'pending approval','".$_SESSION['order'][$key]['price']."')"; $result = mysql_query($query, $connection) or die ("Unable to perfom query<br>$query"); } would I need to put the foreach ($_GET['quantity'] as $key=>$quantity) loop before hand and update the ".$quantity." to $_GET['quantity'][$key]? Quote Link to comment https://forums.phpfreaks.com/topic/88054-multiple-text-box-get-statement-problem/#findComment-450513 Share on other sites More sharing options...
gavin1512 Posted March 4, 2008 Author Share Posted March 4, 2008 Can anyone help me here problem is still about.... would be much appreciated Quote Link to comment https://forums.phpfreaks.com/topic/88054-multiple-text-box-get-statement-problem/#findComment-483004 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.