jwk811 Posted February 18, 2007 Share Posted February 18, 2007 the first page of my order form is all the products listed with a quantity textbox near them and also a check box with any special offers for that product (like this many for this much).. now the quantity and offers in that form have to have unique names so i use an array and make the names quantity[<?php echo $id; ?>] i get the products from the database along with the ids like that.. when i submit that page i want them to check their order.. how can i make all the differnt items that were selected be listed along with the quantity they chose? and then later submit that to the database? Link to comment https://forums.phpfreaks.com/topic/39008-help-with-order-form/ Share on other sites More sharing options...
tllewellyn Posted February 18, 2007 Share Posted February 18, 2007 If I'm understanding you correctly, you can try using a counter to identify each of your field values. So in your form, set up a counter that increments every time you display a new product and tie that counter to the qty box, the id number, and the special offers. For example: <? $count = 0; $result = mysql_query("SELECT * FROM products", $conn); while($row = mysql_fetch_assoc($result)){ echo '<input name="qty' . $count . '" type="text">'; echo '<input name="product' . $count . '" type="hidden">'; echo '<input name="offer' . $count . '" type="checkbox">'; $count++; } ?> <input name="prodcount" type="hidden" value="<? echo $count; ?>"> Then when the form is submitted, if(isset($_POST['Submit'])){ for($i = 0; $i < $_POST['prodcount']; $i++){ if($_POST['qty' . $i] > 0){ $query = "INSERT INTO orders (productid, qty, offers) VALUES ('{$_POST['product' . $i]}', '{$_POST['qty' . $i]}'"; if(isset($_POST['offer' . $i])){ $query .= ", '1'"; } else{ $query .= ", '0'"; } $query .= ")"; mysql_query($query, $conn); }}} Of course, you'll adapt this to whatever specific application you need, particularly the INSERT query. Hope this helps you out, Cheers, Trev Link to comment https://forums.phpfreaks.com/topic/39008-help-with-order-form/#findComment-187824 Share on other sites More sharing options...
jwk811 Posted February 18, 2007 Author Share Posted February 18, 2007 great thanks.. would anyone know how I could show that to the customer instead.. I want to put it in a table like this, instead of inserting it into the database right away (not until i get all information a few more pages down).. ItemUnit PriceTotal $qty x $item$price$qty * $price [td colspan=2]Sub-Total All the items need to be listed, I put one to show you how I need it. So I would probably have to figure out how to do the for looping, correct? Remember the only information that I'm getting from the form is quantity and if they selected to take the offer, so when they type in the quantity it is in a form with a name of quantity[(and the id here] and I get the id of the product from the db. Now since I have, say quantity[1] that they selected.. i need to select the price and item from the db where id = that id in the brackets. And I need to do this for every item they pick. Once I have the item and price from the db and the qty they chose im all set there. The sub total will need to add all the products they chose times the qty.. Please help im desprite here lol Link to comment https://forums.phpfreaks.com/topic/39008-help-with-order-form/#findComment-188032 Share on other sites More sharing options...
jwk811 Posted February 18, 2007 Author Share Posted February 18, 2007 anyone? Link to comment https://forums.phpfreaks.com/topic/39008-help-with-order-form/#findComment-188121 Share on other sites More sharing options...
jwk811 Posted February 18, 2007 Author Share Posted February 18, 2007 bump.. Link to comment https://forums.phpfreaks.com/topic/39008-help-with-order-form/#findComment-188154 Share on other sites More sharing options...
jwk811 Posted February 18, 2007 Author Share Posted February 18, 2007 ok then that should do fine tllewellyn, thank you very much for your help! Link to comment https://forums.phpfreaks.com/topic/39008-help-with-order-form/#findComment-188259 Share on other sites More sharing options...
yzerman Posted February 18, 2007 Share Posted February 18, 2007 pass the values to the next page in the order form using hidden inputs (that was posted already, just not explained in the code that was posted), and submit the data all at once in the confirm order page. see this thread http://www.phpfreaks.com/forums/index.php?topic=118262.msg483184 Link to comment https://forums.phpfreaks.com/topic/39008-help-with-order-form/#findComment-188260 Share on other sites More sharing options...
jwk811 Posted February 19, 2007 Author Share Posted February 19, 2007 yes i know how to do that but not how to show them.. i think i can figure it out from what i already learnt.. thanks Link to comment https://forums.phpfreaks.com/topic/39008-help-with-order-form/#findComment-188288 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.