Jump to content

help with order form


jwk811

Recommended Posts

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
Share on other sites

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
Share on other sites

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