PHP弹出sql查询结果

时间:2017-01-23 08:27:55

标签: javascript php mysql

我正在编写库存管理系统,我想弹出一个带有sql查询结果值的框,如果可能的话,可以直接从这个弹出窗口打印。以下是我的表格。所有值都相应更新。

该表是Stock_details,包含列id,stock_id,stock_name,stock_quantity,supplier_id,company_price,selling_price,category,serial_no,bar_code,po_number,location,user_name,do_number,status,date,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:pavalanath.suriya@kerry.com?subject=Kerry%20ICT%20Inventory%20Management%20System">Kerry ICT Site Services</a>.</p>.
            </p>

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

        </body>
    </html>

1 个答案:

答案 0 :(得分: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'))")) {

Pop Up&amp;印花 我创建了一个页面来查询最后更新的对象并添加了printpage()