如何以单一顺序添加更多产品

时间:2013-10-11 10:10:21

标签: javascript php

我有一个页面book_order.php ...当我填写详细信息并在提交后,所有详细信息都保存在表order_management中。我想要的是提交后,我需要一个弹出窗口,询问“你想添加/预订更多产品吗?”如果按下是...那个order_id会被记住,下次预订必须在同一个order_id上完成...我怎么能这样做....?

我将数据保存在表“order_management”中,其中我将order_id定义为自动递增字段..我的问题是在我记住下一个事务的order_id之后...我怎么能将它插入表中?< / p>

    <?php

if(isset($_POST['submit']))
{
extract($_POST);

$order_date=date("Y-m-d");

$sql=mysql_query("select sku,quantity_in_stock,sold_quantity,crdate from stock_info where product_name = '$prod'");
$array=mysql_fetch_array($sql);
$sku = $array[0];
$qis = $array[1];
$sold_quan = $array[2];
$crdate = $array[3];

$sql2=mysql_query("INSERT INTO order_management(order_date,brand,product,price,customer_name,phone_number,email,address,quantity,channel,courier,order_status,sku)
VALUES
('$order_date','$brand','$prod','$pri','$customername','$phonenumber', '$email','$address','$quantity','$channel','$courier','booked','$sku')");



if($sql2)
{
echo "<div class='da-message success'>Successfully Booked Your Order</div>"; 

}
else 
{
die(mysql_error());
}


$quantity_left = $qis - $quantity;
$sold_quan = $sold_quan + $quantity;

$diff_in_days = (strtotime($order_date) - strtotime($crdate))/(60 * 60 * 24);
$expctd_stock=round((7*$quantity_left)/$diff_in_days);
//echo $expctd_stock;



$sql3 =mysql_query("UPDATE stock_info SET quantity_in_stock = '$quantity_left',last_sold_date='$order_date', sold_quantity='$sold_quan', expected_stock='$expctd_stock' WHERE sku='$sku'");
/*$sql3 = mysql_query("update order_management set sku='$sku' where order_date=''");*/

}
?>

<form id="da-ex-validate1" class="da-form" method="post" action="">


                                           <div class="da-form-row">
                                         <label>Brand<span class="required">*</span></label>
                                                <div class="da-form-item small">
                                                    <!--<input type="text" name="brand"  id="brand" class="required" value=""/>-->
                                                    <select name="brand" id="brand" onChange="retrievedata(this.value)">
                                                    <option value="">--- select brand ---</option>
                                                    <?php
                                                    $ord=mysql_query("select * from brand_info");

                                                    while($ord1=mysql_fetch_array($ord))
                                                    {

                                                    ?>  
                                                       <option value="<?php echo $ord1['brand'];?>"><?php echo $ord1['brand'];?></option> 

                                                       <?php

                                                       }
                                                       ?>   
                                                     </select>
                                                </div>
                                            </div>
                                            <div class="da-form-row">
                                         <label>Product<span class="required">*</span></label>
                                                <div class="da-form-item small">
                                                    <select name="prod" id="prod" onChange="retrievequantity(this.value)">
                                                    <option value="">--- select product  ---</option>
                                                    </select>



                                                </div>
                                            </div> 
                                           <div class="da-form-row">
                                         <label>Customer name<span class="required">*</span></label>
                                                <div class="da-form-item small">
                                                    <input type="text" name="customername"  id="customername" class="required char" value=""/>
                                                </div>
                                            </div>
                                            <div class="da-form-row">
                                         <label>Phone Number<span class="required">*</span></label>
                                                <div class="da-form-item small">
                                                    <input type="text" name="phonenumber"  id="phonenumber" class="required number" value=""/>
                                                </div>
                                            </div> 

                                            <div class="da-form-row">
                                         <label>Email<span class="required">*</span></label>
                                                <div class="da-form-item small">
                                                    <input type="text" name="email"  id="email" class="required email" value=""/>
                                                </div>
                                            </div>
                                            <div class="da-form-row">
                                         <label>Address<span class="required">*</span></label>
                                                <div class="da-form-item small">
                                              <textarea name="address" id="address" class="required"></textarea>

                                                </div>
                                            </div>

                                          <div class="da-form-row">
                                         <label>Quantity<span class="required">*</span></label>
                                                <div class="da-form-item small">

                                                    <select name="quantity" id="quantity">
                                                    <option value=""> --- select Quantity--- </option>
                                                     </select>

                                                </div>
                                            </div>

                                          <div class="da-form-row">
                                         <label>Total Price<span class="required">*</span></label>
                                                <div class="da-form-item small">
                                                    <input type="text" name="pri" id="pri" class="required number" value=""/>
                                                </div>
                                            </div>


                                          <div class="da-form-row">
                                         <label>Courier<span class="required"></span></label>
                                                <div class="da-form-item small">
                                                    <!--<input type="text" name="courier"  id="courier" class="required" value=""/>-->
                                                    <select name="courier" id="courier">
                                                    <option value=""> ---select courier --- </option>
                                                    <?php
                                                    $ord=mysql_query("select courier_name from courier_info");

                                                    while($ord1=mysql_fetch_array($ord))
                                                    {

                                                    ?>  
                                                       <option value="<?php echo $ord1['courier_name'];?>"><?php echo $ord1['courier_name'];?></option> 

                                                       <?php

                                                       }
                                                       ?>   
                                                     </select>

                                                </div>
                                            </div> 

                                             <div class="da-form-row">
                                         <label>Channel<span class="required"></span></label>
                                                <div class="da-form-item small">
                                                    <!--<input type="text" name="channel"  id="channel" class="required" value=""/>-->
                                                    <select name="channel" id="channel">
                                                    <option value=""> --- select channel ---</option>
                                                    <?php
                                                    $ord=mysql_query("select channel from channel_info");

                                                    while($ord1=mysql_fetch_array($ord))
                                                    {

                                                    ?>  
                                                       <option value="<?php echo $ord1['channel'];?>"><?php echo $ord1['channel'];?></option> 

                                                       <?php

                                                       }
                                                       ?>   
                                                     </select>
                                                </div>
                                            </div>
                                          <div class="da-button-row">
                                            <input type="submit"  name="submit"  value="submit" onclick="confirm()" class="da-button red" />

                                        </div>

                                       </fieldset>
                                    </form>

  </div>
            <!-- End of .grid_4 --> </div>
            </div>

     <script>
function retrievedata(data)
{
var option_html = "";

<?php
$sql=mysql_query("SELECT distinct brand,product_name FROM stock_info");
while($ord1=mysql_fetch_array($sql))
{

?>
    if(data == '<?php echo $ord1['brand']; ?>')
    {
        option_html += "<option><?php echo $ord1['product_name']; ?></option>";
        /*alert(option_html);*/
    }
<?php
}

?>
var par = document.getElementById("prod");
par.innerHTML = "<option>--- select product ---</option>"+option_html;
}

function retrievequantity(product)
{
var option_quantity_html = "";

<?php
$sql=mysql_query("SELECT product_name, quantity_in_stock FROM stock_info");
while($ord2=mysql_fetch_array($sql))
{
$i=1;
?>
    if(product == '<?php echo $ord2['product_name']; ?>')
    {
        <?php
        while($i<=intval($ord2['quantity_in_stock'])){?>
        option_quantity_html += "<option><?php echo $i++; ?></option>";
        <?php }?>
    }
<?php
}

?>

var par = document.getElementById("quantity");
par.innerHTML = option_quantity_html;
}

</script>   

3 个答案:

答案 0 :(得分:0)

<强> HTML

<input type="button" id="btn" name="btn" onclick='return add_data()'/>

<强> JS

<script type="text/javascript">
function add_data() 
{
    var ans = confirm("Want to add more?");
    if(ans)
    { return true; // ur code for add new data again }
    else
    { return false; }
}
</script>

答案 1 :(得分:0)

您应该使用:

//Retrieve last order ID inserted
$id = mysql_insert_id();

并将其存储在$ _SESSION或$ _COOKIE

答案 2 :(得分:0)

您可以将order_id保存在php $_SESSION变量中并检查其中是否存在。然后在下一个订单中使用$orderId。 我还建议重构你的代码并为前端添加jQuery,并可能将你的代码放入php类。