2013-10-11 27 views
1

我有一個頁面book_order.php ...當我填寫詳細信息並提交後,所有詳細信息都保存在一個表order_management中。我想要的是提交後一次,我需要一個彈出窗口詢問「你想添加/預訂更多產品嗎?」如果按是...那個order_id被記住,並且下一次預訂必須在同一個order_id上完成...我怎麼能這樣做....?如何以單一順序添加更多商品

我將數據保存在表「order_management」中,其中我將order_id定義爲自動遞增的字段..我的問題是在我記住下一個事務的order_id之後的一次......我如何將它插入表中?

<?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> 
+0

你有試過什麼嗎?最好的辦法是用ajax請求提交你的訂單,如果訂單被正確插入,你就會有一個ajax事件在ajax請求成功完成後觸發。在那個事件中你實際上會觸發你的對話框 –

+0

,問題是更新order_id – sashh

回答

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

你應該使用:

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

並將其存儲在$ _SESSION或$ _COOKIE中

0

您可以將order_id保存在php $_SESSION變量中,並檢查它是否存在。然後在下一個訂單中使用該$orderId。 我也建議重構你的代碼,併爲前端添加jQuery,也許把你的代碼放到一個php類中。

+0

更新表中的order_id是最大的問題,因爲它是自動遞增的fied – sashh

+0

從你的描述中讀取,'single booking'是一個訂單獨特的'order_id'和一些數據(產品等)。當你想添加另一個訂單或預訂時,你想保持相同的'order_id'正確嗎?如果以上所有內容都是正確的,那麼您需要修改數據庫表結構以爲獨特的'order_id'提供一個單獨的列,並且可能會添加一個名爲'booking_id'的列? – Patryk

+0

我創建了一個具有相同結構的新表,其中order_id不是唯一的,並且正在插入它 – sashh

相關問題