SocomNegotiator Posted July 21, 2008 Share Posted July 21, 2008 I have everything working...however on the form you will notice that there is only one submit. Well there can be multiple items as the result of an order. And the user can change the quantity of each individual item...now how do I insert this into the order table with the new quantity of each item? Here is my code: <?php if(!defined('IN_SCRIPT')) header('Location: '); $skin->set_global_vars(array('page_title' => 'reorder')); if(!$user->logged_in()) { header("Location: {$_config['HTTP_INDEX']}?page=account.login"); $skin->buffer_drop_rest(); } $order_number = $_POST['order_number']; //BEGIN: Form Processing: if(isset($_POST['submit'])) { $order_number = $_POST['order_number']; //get the next order_number in line $db->query("SELECT * FROM `order` ORDER BY order_number DESC LIMIT 1") or die(mysql_error()); $number = $db->fetch_array(); $num = 1; if($num = $number['order_number']) $num = $number['order_number'] + 1; elseif($number['order_number'] == "") $num = 1; else $num = $num; //THIS PART IS THE ONLY PART THAT NEEDS CHANGED...I NEED A WAY TO INSERT THE NEW QUANTITY THAT THEY CHOOSE $res = mysql_query("SELECT * FROM `order` WHERE order_number = '$order_number'") or die(mysql_error()); while($r = mysql_fetch_array($res)){ $inserted=$db->query("INSERT INTO `order` (`order_number`,`pre_order_id` , `item_id` , `amount` , `user_id` ) VALUES (".$num.",".$r['pre_order_id'].", ".$r['item_id'].", ".$r['amount'].", ".$r['user_id'].")") or die (mysql_error()); //REST IS CORRECT...I JUST CAN'T FIGURE OUT HOW TO ADD THE MULTIPLE ITEMS WITH THEIR NEW QUANTITY // track the id's of the new inserts $insert_ids[] = mysql_insert_id(); } if($error){ echo $error; // remove any rows that HAVE been inserted from the pre_order table $ids = implode("', '", $insert_ids); if($inserted){ echo "Your order has been re-submitted."; } else { echo "Could not re-submit your order Error: ".mysql_error(); } } else { if($inserted){ echo "Your order has been re-submitted."; } else { echo "Could not re-submit your order Error: ".mysql_error(); } } } $db->query("SELECT item.id, item.name, item.description, order.id, order.amount, order.user_id, order.order_number FROM `order` LEFT JOIN `item` ON order.item_id = item.id WHERE order_number = ' $order_number '") or die(mysql_error()); ?> <style type="text/css"> .menu22 ul{ margin: 0px; padding: 0px; float: left;} .menu22 ul li{ display: inline; margin:2px 5px 5px 20px;} </style> <div class="menu22" align="left"> <ul> <?php while($row = $db->fetch_array()) { ?> <form id='reorder_form' action='?page=reorder' method='post'><input type='hidden' name='order_number' value='<?=$row['order_number']?>'/> <li> <li>Item Name: <?=$row['name']?></li><br /> <ul style="width: 200px; height: 125px;"> <li>Quantity: <input type='text' name='amount' size='5' value='<?=$row['amount']?>' /><br /></li> </ul> </li> <?php } ?> </ul> <br style="clear: left" /> </div> <center><input type='submit' name='submit' value='Re-Submit Order'/></center> </form> </div> <br /> <br /> Link to comment https://forums.phpfreaks.com/topic/115792-solved-phpmysql-insert-multiple-items-on-submit/ Share on other sites More sharing options...
SocomNegotiator Posted July 21, 2008 Author Share Posted July 21, 2008 Ok well that might be a little confusing...so really all I need to know is, is there a way that if I have lets say 2 items that come as the result of the form while statement...will/can I when I submit Re-Submit Order get the amount for both items in the $_POST['amount']...? I mean as it sits right now I can do the whole $_POST['amount'], but doing this will only use the first items quantity...so if the first items was changed to 4 and the second changed to 60. Well both would be 4... Link to comment https://forums.phpfreaks.com/topic/115792-solved-phpmysql-insert-multiple-items-on-submit/#findComment-595253 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.