September 9, 201313 yr Hello everyone,Pls i have a challenge in which i need your assistance. I have a product place order form where customers select the product they want from a list, enter the amount, the quantity and select the measurement. By submitting this form, i want the items submitted to be sent into my mail. This is my code below;order-product.php <form name="form1" method="post" action=""> Name: <input name="name1" type="text" class="input" id="name1" value="<?php echo $name1; ?>" maxlength="50"> Address: <input name="address1" type="text" class="input" id="address1" value="<?php echo $address1; ?>" maxlength="100"> <table width="90%" border="0" cellpadding="3" cellspacing="0" class="border"> <tr> <td width="8%" align="center" valign="middle" bgcolor="#666666" class="style1"> </td> <td width="40%" align="center" valign="middle" bgcolor="#666666" class="style1"><strong>Products</strong></td> <td width="20%" align="center" valign="middle" bgcolor="#666666" class="style1"><strong>Amount ($) </strong></td> <td colspan="2" align="center" valign="middle" bgcolor="#666666" class="style1"><strong>Quantity</strong></td> </tr> <tr> <td align="center" valign="middle" class="border_bottom"><label> <input name="product[1]" type="checkbox" id="product[1]" value="Beans"> </label></td> <td align="left" valign="middle" class="border_bottom">Beans</td> <td align="center" valign="middle" bgcolor="#E3FBE1" class="border_bottom"><label> <input name="amount1" type="text" class="input2" id="amount1" size="9"> </label></td> <td width="16%" align="center" valign="middle" class="border_bottom"> <select name="measure1" class="input2" id="measure1"> <option selected="selected" value="" <?php if (!(strcmp("", $measure))) {echo "selected=\"selected\"";} ?>>Select</option> <option value="Litres" <?php if (!(strcmp("Litres", $measure))) {echo "selected=\"selected\"";} ?>>Litres</option> <option value="Kg" <?php if (!(strcmp("Kg", $measure))) {echo "selected=\"selected\"";} ?>>Kg</option> <option value="Lb" <?php if (!(strcmp("Lb", $measure))) {echo "selected=\"selected\"";} ?>>Lb</option> </select> </td> <td width="16%" align="center" valign="middle" class="border_bottom"> <input name="qty1" type="text" class="input2" id="qty1" value="" size="9"> </td> </tr> <tr> <td align="center" valign="middle" class="border_bottom"><input name="product[2]" type="checkbox" id="product[2]" value="Breadfruith"></td> <td align="left" valign="middle" class="border_bottom">Breadfruith</td> <td align="center" valign="middle" bgcolor="#E3FBE1" class="border_bottom"><input name="amount2" type="text" class="input2" id="amount2" size="9"></td> <td align="center" valign="middle" class="border_bottom"><select name="measure2" class="input2" id="measure2"> <option selected="selected" value="" <?php if (!(strcmp("", $measure))) {echo "selected=\"selected\"";} ?>>Select</option> <option value="Litres" <?php if (!(strcmp("Litres", $measure))) {echo "selected=\"selected\"";} ?>>Litres</option> <option value="Kg" <?php if (!(strcmp("Kg", $measure))) {echo "selected=\"selected\"";} ?>>Kg</option> <option value="Lb" <?php if (!(strcmp("Lb", $measure))) {echo "selected=\"selected\"";} ?>>Lb</option> </select></td> <td align="center" valign="middle" class="border_bottom"><input name="qty2" type="text" class="input2" id="qty2" size="9"></td> </tr> <tr> <td align="center" valign="middle" class="border_bottom"><input name="product[3]" type="checkbox" id="product[3]" value="Cocoyam Flour"></td> <td align="left" valign="middle" class="border_bottom">Cocoyam Flour</td> <td align="center" valign="middle" bgcolor="#E3FBE1" class="border_bottom"><input name="amount3" type="text" class="input2" id="amount3" size="9"></td> <td align="center" valign="middle" class="border_bottom"><select name="measure3" class="input2" id="measure3"> <option selected="selected" value="" <?php if (!(strcmp("", $measure))) {echo "selected=\"selected\"";} ?>>Select</option> <option value="Litres" <?php if (!(strcmp("Litres", $measure))) {echo "selected=\"selected\"";} ?>>Litres</option> <option value="Kg" <?php if (!(strcmp("Kg", $measure))) {echo "selected=\"selected\"";} ?>>Kg</option> <option value="Lb" <?php if (!(strcmp("Lb", $measure))) {echo "selected=\"selected\"";} ?>>Lb</option> </select></td> <td align="center" valign="middle" class="border_bottom"><input name="qty3" type="text" class="input2" id="qty3" size="9"></td> </tr> </table> <input name="Order" type="submit" class="submit" id="Order" value="Submit"> Below is how i have tried to loop the result; if(isset($_POST[Order])){ $name = $_POST[name]; $address = $_POST[address]; for($i=1; $i<=3; $i++){ $product = $_POST["product".$i]; $amount = $_POST["amount".$i]; $qty = $_POST["qty".$i]; $measure = $_POST["measure".$i]; } foreach(($product as $pro), ($amount as $amo), ($qty as $q)){ } For Example if a customer select only two product as below;Bean, $50, 20kgBreadfruit, $20, 5kgHow do i compose the message to be sent this with his/her name and address? Below this is how i did it but its not giving me what i want $msg = "Customer Name: $name\n\nAddress $address\n\nProduct: $product\nAmount: $amount\n$Quantity: $qty $measure"; mail ('my@email.com', 'ORDER', '$msg') Thanks a lot Edited September 9, 201313 yr by rallport Updated because the OP didn't use code tags
September 9, 201313 yr Hi!When you send more options with checkbpxes and you set the name attribute like name="product[]".Then you receive it as $_POST['product'][$i].Have you tried like that?
September 9, 201313 yr Author Thanks Millio05, Yes i did, but the problem is how do I loop the selected products and their respecting amount and quantity and send them to my mail?
September 9, 201313 yr I have just read your problem in more detail.. $details = ""; foreach($_POST['product'] as $key = >$product) { $details .= $product."/n" ; $details .= $_POST['amount'][$key]."/n"; $details .= $_POST['measure'][$key]."/n"; } I have not tested, but I would link the details like above. Edited September 9, 201313 yr by Milli05
September 9, 201313 yr Author Thanks greatly Millio05, That helps me reasonably. I really appreciate is.
Create an account or sign in to comment