chetankayastha Posted August 23, 2011 Posted August 23, 2011 Hi Everyone, I have following problem and could not sort out since 2-3 days. Help. When I insert 20 and 9, The First 2 values are being Re-Inserted. New TABLE products_price_break --------------------------------------- products_price_break_id int(11) NOT NULL products_id int(11) NOT NULL products_pricedecimal (15,4) NOT NULL products_qty int(11) NOT NULL option_discount_priceint (11) NOT NULL option_discount_qtyint (11) NOT NULL products_attributes.php <?php echo '<form name="add_discount" action="" method="post">' . tep_draw_input_field('split', '+ Discount', 'alt="+ Discount" onclick="javascript:window.open(\'' . tep_href_link(FILENAME_ADD_DISCOUNT, 'pid=' . $attributes_values["products_id"], 'NONSSL') . '\',\'' . NAME_WINDOW_SPLIT_PRODUCTS_POPUP . '\',\'menubar=yes,resizable=yes,scrollbars=yes,status=no,location=no,width=650,height=350\')"', false, 'submit') . '</form>'; ?> ---------------------------------------- add_discount.php <script type="text/javascript"> function remove(div) { div.parentNode.parentNode.removeChild(div.parentNode); } function addFeatures() { var d = document.createElement('div'); input1 = document.createElement('input'); input1.setAttribute('type', 'text'); input1.setAttribute('name', 'option_discount_price[]'); input1.setAttribute('style', 'margin-right:13px; margin-top:5px;'); input2 = document.createElement('input'); input2.setAttribute('type', 'text'); input2.setAttribute('name', 'option_discount_qty[]'); input2.setAttribute('style', 'margin-right:15px; margin-top:5px;'); button = document.createElement('input'); button.setAttribute('type', 'button'); button.setAttribute('name', 'btnRemove[]'); button.setAttribute('value', 'Remove'); button.setAttribute('style', 'margin-right:13px; margin-top:5px;'); button.setAttribute('onClick', 'remove(this);'); d.appendChild(input1); d.appendChild(input2); d.appendChild(button); document.getElementById('features').appendChild(d); } </script> <?php if (isset($_POST['insertnew'])){ $product_id = (int)$_GET['pid']; foreach($_POST['option_discount_price'] as $key => $price){ if(!empty($price)){ $quantity = $_POST['option_discount_qty'][$key]; $sql = mysql_query("INSERT INTO products_price_break SET products_id = '$product_id', option_discount_price = '$price', option_discount_qty = '$quantity'"); $result = mysql_query($sql); } } echo $msg = "<table><tr><td class='messageStackSuccess'><img border='0' title=' Success ' alt='Success' src='images/icons/success.gif'> Success: New Price Level & From Quantity has been successfully added.</td></tr></table>"; } ?> <form id="forminsert" name="forminsert" method="post" action=""> <table width="100%" border="0" cellspacing="2" cellpadding="0" align="center"> <tr> <td> </td> <td><input type="button" name="addFeature" value="Next" onClick="addFeatures();" /> </td> <td> </td> </tr> <tr> <td class="main" valign="top">Price Level & Quantity</td> <td><?php if(isset($_GET['pid'])){ $pid = $_GET['pid']; $result = mysql_query("SELECT * FROM products_price_break WHERE products_id = '$pid'"); while($row = mysql_fetch_array($result)){ ?> <input type="text" name="option_discount_price[]" value="<?php echo $row['option_discount_price']; ?>" style="margin-right:10px; margin-top:5px;" /> <input type="text" name="option_discount_qty[]" value="<?php echo $row['option_discount_qty']; ?>" style="margin-right:10px; margin-top:5px;" /> <a href="add_discount.php?action=discount&products_id=<?=$_GET['pid'];?>&id=<?=$row['products_price_break_id']; ?>">Delete</a><br /> <?php } } else { ?> <input type="text" name="option_discount_price[]" style="margin-right:10px;" /> <input type="text" name="option_discount_qty[]" style="margin-right:10px;" /> <?php } ?> <div id="features"></div></td> <td> </td> </tr> <tr> <td colspan="3"><p style="margin-top: 10px;"><?php echo tep_image_submit('button_save.gif', IMAGE_SAVE, 'name="insertnew"') ?> <input type="hidden" name="insertnew" /> <?php echo tep_image_button('button_cancel.gif', IMAGE_CANCEL, 'onclick=\'self.close()\''); ?></p></td> </tr> </table> </form>
Recommended Posts
Archived
This topic is now archived and is closed to further replies.