-4

我有一个页面 *book_order*,用于将订单添加到表 *order_management* 中,其中 order_id 在该表中自动递增。提交此页面后,我希望将 order_id 传递到其他页面 *book_order2* 以在相同的 order_id 下添加产品。为此,我创建了单独的 *order_management2* 表,其中 order_id 不是自动递增的。

我的要求是我想将 order_id 从 book_order 页面传递到 book_order2 页面,并且要记住该变量,直到我继续添加....如果我想添加新订单,我将转到 book_order 页面,否则我会使用 book_order2 页面。

book_order.php

 <div class="grid_4">
   <div class="da-panel">
   <div class="da-panel-header">
   <span class="da-panel-title">
   <img src="images/icons/color/wand.png" alt="" />
   <font face="Cambria" size="7" color="#009900"><b>Book Order</b></font>
   </span>

   </div>
   <div class="da-panel-toolbar top">
   <ul>

   <li><a href="main.php?page=view_orders"><div class="da-button blue large">View all Orders</div></a></li>

   </ul>
   </div>

   <div class="da-panel-content">



   <?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>"; 
           ?>
           <script>

           var r = confirm("want to add more products?");
           if (r == true)
             {
               //x="You pressed OK!";
               window.location = "main.php?page=book_order2";
             }
           else
             {
               //x="You pressed Cancel!";
               window.location = "main.php";
             }

           </script>
           <?php
         }
       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=''");*/

       $sql4 =mysql_query("select order_id from order_management where sku='$sku'");
       $idarray=mysql_fetch_array($sql4);
       $id = $idarray[0];
       //$_SESSION['id'] = $id;
     }
   ?>

   <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" class="da-button grey" />


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




book_order2.php





<?php /*?><?php 
        $id = $_SESSION['id'];
        echo $id;
        ?><?php */?>
<?php
include("includes/db.php");



?>


<div class="grid_4">
  <div class="da-panel">
  <div class="da-panel-header">
  <span class="da-panel-title">
  <img src="images/icons/color/wand.png" alt="" />
  <font face="Cambria" size="7" color="#009900"><b>Book Order</b></font>
  </span>

  </div>
  <div class="da-panel-toolbar top">
  <ul>

  <li><a href="main.php?page=view_orders"><div class="da-button blue large">View all Orders</div></a></li>

  </ul>
  </div>

  <div class="da-panel-content">



  <?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_management2(order_id,order_date,brand,product,price,customer_name,phone_number,email,address,quantity,channel,courier,order_status,sku)
    VALUES
    ('$id','$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>"; 
          ?>
          <script>

          var r = confirm("want to add more products?");
          if (r == true)
            {
              //x="You pressed OK!";
              window.location = "main.php?page=book_order2";
            }
          else
            {
              //x="You pressed Cancel!";
              window.location = "main.php";
            }

          </script>
          <?php
        }
      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=''");*/

      //$sql4 =mysql_query("select order_id from order_management where sku='$sku'");
      //$idarray=mysql_fetch_array($sql4);

    }
?>

<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" class="da-button grey" />
  <?php /*?><a href="book_order2.php?&id=<?php echo $id; ?>" name="submit" value="submit"  class="da-button grey">Book Order</a<?php */?>

  </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>                      
4

2 回答 2

0

我会用ajax. 例如:

$(document).ready(function()
{
    $("form").on('submit',function(event)
    {
        event.preventDefault();

        data = "var=data";

        $.ajax
        ({
            type: "GET",
            url: "parser.php",
            data: data
        }).done(function(msg)
            {

                alert(msg);
            });
    });
});

它将发送GETparser.php. 并且数据字段将data$_GET['var']

于 2013-10-17T16:40:53.897 回答
0

您可以将订单号存储在会话中。这样,它将在页面之间受到保护和持久化。

当您在 中插入订单时book_order.php,将其存储在会话中:

$sql2=mysql_query(....); // inserting

if($sql2){
    $_SESSION['order_id'] = mysql_insert_id();
}

现在,book_order2.php您可以在插入产品之前检索订单 ID:

$id = $_SESSION['order_id'];
// insert product with order_id = $id

为了使用 PHP 会话,您必须在使用会话session_start()的任何脚本的开头调用 l。如果你有一个全局/标题包含,那么你可以在那里做。


旁注:

  • mysql_*已弃用。考虑升级到 PDO 或 MySQLi。是一个很好的 PDO 教程,特别是如果您从mysql_*.
  • 使用带有绑定参数的 Prepared Statement,而不是将变量连接到 SQL 中。
于 2013-10-17T16:32:30.680 回答