2017-01-23 63 views
0

我在寫一個庫存管理系統,我想彈出一個包含sql查詢結果值的框,如果可能的話直接從這個彈出框中打印。以下是我的表格。所有值都相應更新。PHP彈出與SQL查詢結果

該表是stock_details列id,stock_id,stock_name,stock_quantity,supplier_id,company_price,selling_price,類別,serial_no,bar_code,po_number,位置,用戶名,do_number,狀態,日期,kerry_barcode。

當我提交新購買時,它將使用add_purchase表單上的值更新數據庫,但不會彈出帶有kerry_barcode值的框。在這裏我想要打印按鈕,所以我可以將其打印出生成的條形碼。

例如:

Kerry_barcode = stock_id + category + location 

kerry_barcode = PICT43 - Desktop - MY-JHB-KGBS 

我已經跑在我的分貝以下查詢,並將其填充;

SELECT CONCAT(stock_id, ' - ', category, ' - ', location) AS kerry_barcode FROM stock_details. 

我嘗試過使用;

<td> 
      <?php 
      $kerrybarcode = $db->query("SELECT CONCAT(stock_id, ' - ', category, ' - ', location) AS kerry_barcode FROM stock_details "); 
      ?> 
      &nbsp; 
      <td><span class="man">*</span>Kerry&nbsp; Barcode:</td> 
      <td><input name="kerrybarcode" type="text" id="kerrybarcode" maxlength="400" 
      class="round default-width-input" 
      value="<?php echo isset($kerrybarcode) ? $kerrybarcode : ''; ?>"/></td> 

它更新數據庫成功地但Kerry_username沒有更新。

我需要幫助來獲得這個查詢的權利,並彈出一個框中填充值與最後更新的ID與打印按鈕。

我使用最新的mysql maria db和來自xampp的php myadmin。

以下是我的add_purchase頁面。

<?php 
    include_once("init.php"); 
    ?> 
    <!DOCTYPE html> 

    <html lang="en"> 
     <head> 
      <meta charset="utf-8"> 
      <title>Kerry - Add Purchase</title> 

      <!-- Stylesheets --> 
      <link href='http://fonts.googleapis.com/css? family=Droid+Sans:400,70' rel='stylesheet'> 
      <link rel="stylesheet" href="css/style.css"> 
      <link rel="stylesheet" href="js/date_pic/date_input.css"> 
      <link rel="stylesheet" href="lib/auto/css/jquery.autocomplete.css"> 

      <!-- Optimize for mobile devices --> 
      <meta name="viewport" content="width=device-width, initial-scale=1.0"/> 

      <!-- jQuery & JS files --> 
      <?php include_once("tpl/common_js.php"); ?> 
      <script src="js/script.js"></script> 
      <script src="js/date_pic/jquery.date_input.js"></script> 
      <script src="lib/auto/js/jquery.autocomplete.js "></script> 
      <script src="js/add_stock.js"></script> 

      <!-- jQuery & JS files --> 
     <?php include_once("tpl/common_js.php"); ?> 
     <script src="js/script.js"></script> 
      <script src="js/date_pic/jquery.date_input.js"></script> 
      <script src="lib/auto/js/jquery.autocomplete.js "></script> 

      <script> 
     /*$.validator.setDefaults({ 
      submitHandler: function() { alert("submitted!"); } 
     });*/ 
     $(document).ready(function() { 
      $("#supplier").autocomplete("supplier1.php", { 
      width: 160, 
      autoFill: true, 
      selectFirst: true 
     }); 
      $("#category").autocomplete("category.php", { 
      width: 160, 
      autoFill: true, 
      selectFirst: true 
     }); 
      $("#name").autocomplete("stockname.php", { 
      width: 160, 
      autoFill: true, 
      selectFirst: true 
     }); 
      $("#location").autocomplete("location.php", { 
      width: 160, 
      autoFill: true, 
      selectFirst: true 
     }); 
      // validate signup form on keyup and submit 


     }); 
    function numbersonly(e){ 
      var unicode=e.charCode? e.charCode : e.keyCode 
      if (unicode!=8 && unicode!=46 && unicode!=37 && unicode!=38 && unicode!=39 && unicode!=40 && unicode!=9){ //if the key isn't the backspace key (which we should allow) 
      if (unicode<48||unicode>57) 
      return false 
     } 
     } 
     </script> 

     </head> 
     <body> 

      <!-- TOP BAR --> 
      <?php include_once("tpl/top_bar.php"); ?> 
      <!-- end top-bar --> 


      <!-- HEADER --> 
      <div id="header-with-tabs"> 

       <div class="page-full-width cf"> 

        <ul id="tabs" class="fl"> 
         <li><a href="dashboard.php" class="active-tab dashboard-tab">Dashboard</a></li> 
      <!-- <li><a href="view_sales.php" class="sales-tab">Sales</a></li> --> 
      <!-- <li><a href="view_customers.php" class=" customers-tab">Customers</a></li> --> 
         <li><a href="view_purchase.php" class="purchase-tab">Purchase</a></li> 
         <li><a href="view_supplier.php" class=" supplier-tab">Supplier</a></li> 
         <li><a href="view_product.php" class=" stock-tab">Stocks/Products</a></li> 
      <!-- <li><a href="view_payments.php" class="payment-tab">Payments/Outstandings</a></li> --> 
         <li><a href="view_report.php" class="report-tab">Reports</a></li> 
        </ul> 
        <!-- end tabs --> 


        <!-- The logo will automatically be resized to 30px height. --> 
        <a href="#" id="company-branding-small" class="fr"><img src="<?php 
      if (isset($_SESSION['logo'])) { 
       echo "upload/" . $_SESSION['logo']; 
      } else { 
       echo "upload/Kerry_Group_Logo.png"; 
      } 
      ?>" alt="Kerry ICT IM System"/></a> 

       </div> 
       <!-- end full-width --> 

      </div> 
      <!-- end header --> 


      <!-- MAIN CONTENT --> 
      <div id="content"> 

       <div class="page-full-width cf"> 

        <div class="side-menu fl"> 

         <h3>Purchase Management</h3> 
         <ul> 
          <li><a href="add_purchase.php">Add Purchase</a></li> 
          <li><a href="view_purchase.php">View Purchase </a></li> 
         </ul> 

        </div> 
        <!-- end side-menu --> 

        <div class="side-content fr"> 

         <div class="content-module"> 

          <div class="content-module-heading cf"> 

           <h3 class="fl">Add Purchase</h3> 
           <span class="fr expand-collapse-text">Click to collapse</span> 
           <span class="fr expand-collapse-text initial-expand">Click to expand</span> 

          </div> 
          <!-- end content-module-heading --> 

          <div class="content-module-main cf"> 


           <?php 
         //Gump is library for Validatoin 
         if (isset($_POST['name'])) { 
          $_POST = $gump->sanitize($_POST); 
          $gump->validation_rules(array(
           'name' => 'required|max_len,100|min_len,3', 
           'stockid' => 'required|max_len,200', 
           'sell' => 'max_len,200', 
           'cost' => 'required|max_len,200', 
           'supplier' => 'max_len,200', 
           'category' => 'max_len,200', 
           'username' => 'max_len,200', 
           'location' => 'max_len,200', 
           'serialno' => 'required|max_len,200', 
           'ponumber' => 'required|max_len,200', 
           'barcode' => 'required|max_len,200', 
           'donumber' => 'required|max_len,200', 
           'status' => 'max_len,200', 
           'date' => 'max_len,200', 
           'kerrybarcode' => 'max_len,200' 
          )); 
          $gump->filter_rules(array(
           'name' => 'trim|sanitize_string|mysqli_escape', 
           'stockid' => 'trim|sanitize_string|mysqli_escape', 
           'sell' => 'trim|sanitize_string|mysqli_escape', 
           'cost' => 'trim|sanitize_string|mysqli_escape', 
           'category' => 'trim|sanitize_string|mysqli_escape', 
           'supplier' => 'trim|sanitize_string|mysqli_escape', 
           'username' => 'trim|sanitize_string|mysqli_escape', 
           'location' => 'trim|sanitize_string|mysqli_escape', 
           'serialno' => 'trim|sanitize_string|mysqli_escape', 
           'ponumber' => 'trim|sanitize_string|mysqli_escape', 
           'barcode' => 'trim|sanitize_string|mysqli_escape', 
           'donumber' => 'trim|sanitize_string|mysqli_escape', 
           'status' => 'trim|sanitize_string|mysqli_escape', 
           'date' => 'trim|sanitize_string|mysqli_escape', 
           'kerrybarcode' => 'trim|sanitize_string|mysqli_escape' 

          )); 
          $validated_data = $gump->run($_POST); 
          $name = ""; 
          $stockid = ""; 
          $sell = ""; 
          $cost = ""; 
          $supplier = ""; 
          $category = ""; 
          $username = ""; 
          $location = ""; 
          $serialno = ""; 
          $ponumber = ""; 
          $barcode = ""; 
          $donumber = ""; 
          $status = ""; 
          $date= ""; 
          $kerrybarcode= ""; 
          if ($validated_data === false) { 
           echo $gump->get_readable_errors(true); 
          } else { 
           $name = mysqli_real_escape_string($db->connection, $_POST['name']); 
           $stockid = mysqli_real_escape_string($db->connection, $_POST['stockid']); 
           $sell = mysqli_real_escape_string($db->connection, $_POST['sell']); 
           $cost = mysqli_real_escape_string($db->connection, $_POST['cost']); 
           $supplier = mysqli_real_escape_string($db->connection, $_POST['supplier']); 
           $category = mysqli_real_escape_string($db->connection, $_POST['category']); 
           $username = mysqli_real_escape_string($db->connection, $_POST['username']); 
           $location = mysqli_real_escape_string($db->connection, $_POST['location']); 
           $serialno = mysqli_real_escape_string($db->connection, $_POST['serialno']); 
           $ponumber = mysqli_real_escape_string($db->connection, $_POST['ponumber']); 
           $barcode = mysqli_real_escape_string($db->connection, $_POST['barcode']); 
           $donumber = mysqli_real_escape_string($db->connection, $_POST['donumber']); 
           $status = mysqli_real_escape_string($db->connection, $_POST['status']); 
           $date = mysqli_real_escape_string($db->connection, $_POST['date']); 
           $kerrybarcode = mysqli_real_escape_string($db->connection, $_POST['kerrybarcode']); 
           $count = $db->countOf("stock_details", "stock_id ='$stockid'"); 
           if ($count == 1) { 
            echo "<font color=red> Duplicate Entry. Please Verify</font>"; 
           } else { 
            if ($db->query("insert into stock_details(stock_id,stock_name,supplier_id,company_price,selling_price,category,user_name,location,serial_no,po_number,bar_code,do_number,status) values('$stockid','$name','$supplier','$cost','$sell','$category','$username','$location','$serialno','$ponumber','$barcode','$donumber','$status')")) { 
             echo "<br><font color=green size=+1 > [ $name ] Stock Details Added !</font>"; 
             $db->query("insert into stock_avail(name,quantity) values('$name',0)"); 

           } else 
             echo "<br><font color=red size=+1 >Problem in Adding !</font>"; 
           } 
          } 
         } 
         ?> 

           <form name="form1" method="post" id="form1" action=""> 


          <table class="form" border="0" cellspacing="0" cellpadding="0"> 
           <tr> 
            <?php 
            $max = $db->maxOfAll("id", "stock_details"); 
            $max = $max + 1; 
            $autoid = "PICT" . $max . ""; 
            ?> 
            <td><span class="man">*</span>Asset&nbsp;ID:</td> 
            <td><input name="stockid" type="text" id="stockid" readonly="readonly" maxlength="200" 
               class="round default-width-input" 
               value="<?php echo isset($autoid) ? $autoid : ''; ?>"/></td> 

            <td><span class="man">*</span>Name:</td> 
            <td><input name="name" placeholder="Enter Stock Name" type="text" id="name" 
               maxlength="200" class="round default-width-input" 
               value="<?php echo isset($name) ? $name : ''; ?>"/></td> 

            <td>Username:</td> 
            <td><input name="username" placeholder="Enter Employee Name" type="text" id="username" 
               maxlength="200" class="round default-width-input" 
               value="<?php echo isset($username) ? $username : ''; ?>"/></td> 

           </tr> 
           <tr> 
            <td><span class="man">*</span>Cost:</td> 
            <td><input name="cost" placeholder="Enter Cost Price" type="text" id="cost" 
               maxlength="200" class="round default-width-input" 
               onkeypress="return numbersonly(event)" 
               value="<?php echo isset($cost) ? $cost : ''; ?>"/></td> 

            <td><span class="man">*</span>Status:</td> 
            <td> 

            <input name="status" placeholder="Product Status" type="text" id="status" 
               maxlength="200" class="round default-width-input"                     
               value="<?php echo isset($status) ? $status : ''; ?>"/></td> 

            <td>Location:</td> 
            <td><input name="location" placeholder="Enter Site Location" type="text" id="location" 
               maxlength="200" class="round default-width-input" 
               value="<?php echo isset($location) ? $location : ''; ?>"/></td> 

           </tr> 
           <tr> 
            <td>Supplier:</td> 
            <td><input name="supplier" placeholder="Enter Supplier Name" type="text" id="supplier" 
               maxlength="200" class="round default-width-input" 
               value="<?php echo isset($supplier) ? $supplier : ''; ?>"/></td> 

            <td>Category:</td> 
            <td><input name="category" placeholder="Enter Category Name" type="text" id="category" 
               maxlength="200" class="round default-width-input" 
               value="<?php echo isset($category) ? $category : ''; ?>"/></td> 

            <td><span class="man">*</span>Serial Number:</td> 
            <td><input name="serialno" placeholder="Enter Serial Number" type="text" id="serialno" 
               maxlength="200" class="round default-width-input"           
               value="<?php echo isset($serialno) ? $serialno : ''; ?>"/></td> 

           </tr> 

           <tr> 


            <td><span class="man">*</span>DO Number:</td> 
            <td><input name="donumber" placeholder="Enter DO Number" type="text" id="donumber" 
               maxlength="200" class="round default-width-input"           
               value="<?php echo isset($donumber) ? $donumber : ''; ?>"/></td> 

            <td><span class="man">*</span>PO Number:</td> 
            <td><input name="ponumber" placeholder="Enter PO Number" type="text" id="ponumber" 
               maxlength="200" class="round default-width-input"           
               value="<?php echo isset($ponumber) ? $ponumber : ''; ?>"/></td> 


            <td><span class="man">*</span>Barcode:</td> 
            <td><input name="barcode" placeholder="Enter Barcode" type="text" id="barcode" 
               maxlength="200" class="round default-width-input"           
               value="<?php echo isset($barcode) ? $barcode : ''; ?>"/></td> 




           </tr> 


           <tr> 

            <td>Date:</td> 
            <td><input name="date" placeholder="" value="<?php echo date('d M Y');?>" type="text" id="name" 
               maxlength="200" class="round default-width-input" /></td> 
               <td></td> 
               <td></td> 


           </tr> 

           <tr> 
            <td>&nbsp;</td> 
            <td>&nbsp;</td> 
           </tr> 


           <tr> 

            <td></td> 
            <td> 
            <input class="button round blue image-right ic-add text-upper" type="submit" 
               name="Submit" value="Add"> 
             (Control + S) 

            <td align="right"><input class="button round red text-upper" type="reset" name="Reset" 
                  value="Reset"></td> 
            <td> 
            <?php 
            $kerrybarcode = $db->query("SELECT CONCAT(stock_id, ' - ', category, ' - ', location) AS kerry_barcode FROM stock_details "); 
            ?> 
            &nbsp; 
            <td><span class="man">*</span>Kerry&nbsp; Barcode:</td> 
            <td><input name="kerrybarcode" type="text" id="kerrybarcode" maxlength="400" 
               class="round default-width-input" 
               value="<?php echo isset($kerrybarcode) ? $kerrybarcode : ''; ?>"/></td> 
            </td> 
           </tr> 
          </table> 
         </form> 


          </div> 
          <!-- end content-module-main --> 


         </div> 
         <!-- end content-module --> 


        </div> 
       </div> 
       <!-- end full-width --> 

      </div> 
      <!-- end content --> 


      <!-- FOOTER --> 
      <div id="footer"> 
       <p style="text-align:center">For Any Queries Email to <a href="mailto:[email protected]?subject=Kerry%20ICT%20Inventory%20Management%20System">Kerry ICT Site Services</a>.</p>. 
      </p> 

      </div> 
      <!-- end footer --> 

     </body> 
    </html> 

回答

0

解決了它。

剛剛將該SELECT CONCAT(STOCK_ID, ' - ',類別, ' - ',位置添加多個列kerry_barcode

$db->query("insert into stock_details(stock_id,stock_name,supplier_id,company_price,selling_price,category,user_name,location,serial_no,po_number,bar_code,do_number,status,kerry_barcode) values('$stockid','$name','$supplier','$cost','$sell','$category','$username','$location','$serialno','$ponumber','$barcode','$donumber','$status',CONCAT('$stockid',' - ','$name',' - ','$location'))")) { 

拉網&印刷 我犯了一個網頁來查詢最新更新對象並添加了printpage()

+0

將target =「myNewWinsr」添加到添加購買表單上的html按鈕以使用上次更新的對象彈出新頁面。 –