如何用一个按钮做多个帖子

时间:2015-07-07 19:28:05

标签: php mysql sql forms

我正在使用以下代码(invoice.php),并将库存数据发布到" invoice"在一张名为"发票"的桌子下面。我想添加一个名为" salesman"在"发票"下,插入与此页面中的表单邮政编码一致的代码。有谁知道我怎么可以同时插入两个?

<?php 
    $user_obj = new Cl_User();
    if(!empty($_POST)){
        try {
            $user_obj->saveInvoice($_POST);
            $_SESSION['success'] = 'Invoice Saved Successfully!';
            header('Location: invoices.php');exit;
        } catch (Exception $e) {
            $error = $e->getMessage();
        }
    }elseif (isset($_GET['uuid']) && !empty($_GET['uuid'])){
        try {
            $results = $user_obj->getInvoice( $_GET['uuid'] );
        } catch (Exception $e) {
            $_SESSION['error'] = $e->getMessage();
        }
    }elseif (isset($_GET['delete']) && !empty($_GET['delete'])){
        try {
            if( $user_obj->deleteInvoice( $_GET['delete'] )){
                $_SESSION['success'] = 'Invoice Deleted Successfully!';
                header('Location: invoices.php');exit;
            }else{
                $_SESSION['success'] = 'Invoice Not Deleted, Try Again!';
                header('Location: invoices.php');exit;
            }

        } catch (Exception $e) {
            $_SESSION['error'] = $e->getMessage();
        }
    }

    $settings = $user_obj->getSettings();
    //echo "<pre>";print_r( $settings ); echo "</pre>";
    $invoice = array();
    if(!empty( $results )){
        $invoice = json_decode( $results['invoice'], true);
    }
?>


    <!-- Begin page content -->
    <div class="container content-invoice">
        <form action="<?php echo $_SERVER['PHP_SELF']; ?>" id="invoice-form" method="post"  class="invoice-form" role="form" novalidate> 
            <div class="load-animate">
                <input type="hidden" value="<?php echo isset($results['id']) ? $results['id']: ''; ?>" name="data[id]">
                <div class='row'>
                    <div class='col-xs-8 col-sm-8 col-md-8 col-lg-8'>

                    </div>

                    <div class='col-xs-4 col-sm-4 col-md-4 col-lg-4'>
                        <input data-loading-text="Saving Workorder..." type="submit" name="invoice_btn" value="Save Workorder" class="btn btn-success submit_btn invoice-save-top form-control"/>
                    </div>
                </div>

                                    <th width="2%"><input id="check_all" class="formcontrol" type="checkbox"/></th>
                                    <th width="15%">Item No</th>
                                    <th width="38%">Item Name</th>
                                    <th width="15%">Price</th>
                                    <th width="15%">Quantity</th>
                                    <th width="15%">Total</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php if(isset($invoice['data']['Invoice'])&&!empty($invoice['data']['Invoice'])){?>
                                    <?php foreach ( $invoice['data']['Invoice']['itemNo'] as $key=>$item){?>
                                        <tr>
                                            <td> <input class="case" type="checkbox"/> </td>
                                            <td><input value="<?php echo isset($invoice['data']['Invoice']['itemNo'][$key]) ? $invoice['data']['Invoice']['itemNo'][$key]: ''; ?>" type="text" data-type="productCode" name="data[Invoice][itemNo][]" id="itemNo_<?php echo $key+1?>" class="form-control autocomplete_txt" autocomplete="off"></td>
                                            <td><input value="<?php echo isset($invoice['data']['Invoice']['itemName'][$key]) ? $invoice['data']['Invoice']['itemName'][$key]: ''; ?>" type="text" data-type="productName" name="data[Invoice][itemName][]" id="itemName_<?php echo $key+1?>" class="form-control autocomplete_txt" autocomplete="off"></td>
                                            <td><input value="<?php echo isset($invoice['data']['Invoice']['price'][$key]) ? $invoice['data']['Invoice']['price'][$key]: ''; ?>" type="number" name="data[Invoice][price][]" id="price_<?php echo $key+1?>" class="form-control changesNo" autocomplete="off" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"></td>
                                            <td><input value="<?php echo isset($invoice['data']['Invoice']['quantity'][$key]) ? $invoice['data']['Invoice']['quantity'][$key]: ''; ?>" type="number" name="data[Invoice][quantity][]" id="quantity_<?php echo $key+1?>" class="form-control changesNo" autocomplete="off" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"></td>
                                            <td><input value="<?php echo isset($invoice['data']['Invoice']['total'][$key]) ? $invoice['data']['Invoice']['total'][$key]: ''; ?>" type="number" name="data[Invoice][total][]" id="total_<?php echo $key+1?>" class="form-control totalLinePrice" autocomplete="off" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"></td>
                                        </tr>
                                    <?php } ?>
                                <?php }else{?>
                                    <tr>
                                        <td><input class="case" type="checkbox"/></td>
                                        <td><input type="text" data-type="productCode" name="data[Invoice][itemNo][]" id="itemNo_1" class="form-control autocomplete_txt" autocomplete="off"></td>
                                        <td><input type="text" data-type="productName" name="data[Invoice][itemName][]" id="itemName_1" class="form-control autocomplete_txt" autocomplete="off"></td>
                                        <td><input type="number" name="data[Invoice][price][]" id="price_1" class="form-control changesNo" autocomplete="off" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"></td>
                                        <td><input type="number" name="data[Invoice][quantity][]" id="quantity_1" class="form-control changesNo" autocomplete="off" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"></td>
                                        <td><input type="number" name="data[Invoice][total][]" id="total_1" class="form-control totalLinePrice" autocomplete="off" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"></td>
                                    </tr>
                                <?php } ?>
                            </tbody>
                        </table>
                    </div>
                </div>


                        <div class='form-group text-center'>
                            <input data-loading-text="Saving Invoice..." type="submit" name="invoice_btn" value="Save Workorder" class="btn btn-success submit_btn invoice-save-btm"/>
                        </div>

                    </div>

        </form>         
    </div>
    <script src="js/jquery-ui.min.js"></script>
    <script src="js/auto.js"></script>
    <script>
        $('.submit_btn').on('click', function(){
            $(this).button('loading');
        });

        $(document).ready(function(){
            $('.currency').html( $('#currency').val() );
        });

        $('#clientCompanyName').autocomplete({
            source: function( request, response ) {
                $.ajax({
                    url : 'ajax.php',
                    dataType: "json",
                    method: 'post',
                    data: {
                        name_startsWith: request.term,
                        type: 'customerName'
                    },
                    success: function( data ) {
                        response( $.map( data, function( item ) {
                            var code = item.split("|");
                                return {
                                    label: code[1],
                                    value: code[1],
                                    data : item
                                }
                            }));
                        }
                    });
            },
            autoFocus: true,            
            minLength: 1,
            select: function( event, ui ) {
                var names = ui.item.data.split("|");
                $(this).val(names[1]);
                getClientAddress(names[0]);
            }               
        });
        function getClientAddress(id){

             $.ajax({
                 url: "ajax.php",
                 method: 'post', 
                 data:{id:id, type:'clientAddress'},
                 success: function(result){
                    $("#clientAddress").html(result);
                }
            });
        }





    </script>

     <?php ob_end_flush(); ?>
     <?php 
     unset($_SESSION['success'] );
     unset($_SESSION['error']);
     ?> 

     <script src="js/bootstrap.min.js"></script>
    <script src="js/bootstrap-datepicker.js"></script>
  </body>
</html>

0 个答案:

没有答案