Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从laravel中传递的数组对象更新DB::table_Php_Mysql_Arrays_Json_Laravel - Fatal编程技术网

Php 从laravel中传递的数组对象更新DB::table

Php 从laravel中传递的数组对象更新DB::table,php,mysql,arrays,json,laravel,Php,Mysql,Arrays,Json,Laravel,在laravel中,我试图更新几个表和行。我有两个不同的用户要接收和检查的项目 在show.blade.php中,根据用户的不同,我有这个verify按钮和submit按钮 @if (($current_user_id != $saved_receiver_id) && ($saved_receiver_id != $not_yet_received)) <div class="row padder m-b"> <div cl

在laravel中,我试图更新几个表和行。我有两个不同的用户要接收和检查的项目

在show.blade.php中,根据用户的不同,我有这个verify按钮和submit按钮

@if (($current_user_id  != $saved_receiver_id) && ($saved_receiver_id != $not_yet_received))    

    <div class="row padder m-b">
        <div class="col-md-12">
            <label for="received_by" class="pull-left" >Received by:</label> <span class="fa"></span>
            <input type="hidden" name="receiver_id" value="{{ $saved_receiver_id }}" >{{ $receiver_username }}</input>
        </div>
    </div>
    <div class="row padder m-b">
        <div class="col-md-12">
            <label for="received_date" class="pull-left" >Received date:</label> <span class="fa"></span>
            <input type="hidden" name="received_date" value="{{ $received_date }}" >{{ $received_date }}</input>
        </div>
    </div>
    <input type="hidden" name="purchase_orders_id" value="{{ $purchase_order_number }}">
    <input type="hidden" name="checker_id" value="{{ $current_user_id }}">
    <div class="row padder m-b">
        <div class="col-md-12">
            <label for="final_checker_remarks" class="pull-left" >Final Remarks</label>
            <textarea class="form-control col-md-12" name="final_checker_remarks" value="{{ $final_checker_remarks }}" id="final_checker_remarks">{{ $final_checker_remarks }}</textarea>
        </div>
    </div>
    <br />
    <div class="row">
        <div class="col-md-12">
            <button type="button" class="pull-right btn btn-success btn-sm submit-btn" id="update-form-submit" data-action="verified">Verified</button>
        </div>
    </div>
    @else
    <div class="pull-right">
        <div class="btn-group">
            <button type="button" class="btn btn-info btn-sm submit-btn" id="update-form-submit" data-action="submit">Submit List</button>
        </a>
    </div>
@endif

我上面的$.fn.serializeObject=function()似乎有错误,我尝试使用另一个$.fn.serializeObject=function(),它给了我想要的json对象。下面是我现在使用的$.fn.serializeObject=function()

$.fn.serializeObject = function()
{
    var o = {};
    var a = this.serializeArray();
    $.each(a, function() {
        if (o[this.name] !== undefined) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};

对于所有选择要更新的行。当您转储简单值时,您得到了什么?当我在输入中输入一个单词时,例如:hello,表中唯一保存的是字母h。once$items=json_decode($request->items);在保存到数据库之前返回响应,看看您得到了什么新的,当我有3行被更新时,它不再工作了。我收到这个错误:QueryException in Connection.php第636行:SQLSTATE[42000]:语法错误或访问冲突:1064您的SQL语法有错误;检查与您的MariaDB服务器版本相对应的手册,了解第1行“where
purchase\u items
id
is null”附近使用的正确语法(SQL:update
items
Internal join
purchase\u items
on
items
purchase\u items
itemsset
items
度量+其中
purchase\u items
id
为空)
    /* ========================================================================
 *  Initialize Pages
 * ======================================================================== */
    $(initialPages);

/* ========================================================================
 *  Major function
 * ======================================================================== */

/* ==== function to init this page === */
function initialPages($) {

    // if($('#receives-list-table').length){
    //  DataTables("#receives-list-table", "receives");
    // }

    if($('#receiveItems-list-table').length){
            $("#receiveItems-list-table").DataTable({
            responsive: true,
            ordering: false,
        });
    }

    $('#update-form-submit').on('click', function(){
        var action = $(this).data('action');
        updateReceiveItem(action);
    });
    clearInputs();
}

/* === dataTables === */
function DataTables(selector, controller) {
    $(selector).DataTable({
        responsive: true,
        processing: true,
        serverSide: true,
        ajax: url+'/'+controller+'/paginate'
    });
}

function updateReceiveItem(action){
    loadingModal('show','Updating ....');
    ajaxCsrfToken();

    var data = $('#receiveItems_id').serializeArray();
        data = JSON.stringify(data);
        // data = JSON.parse(data);
        data = JSON.stringify($('#receiveItems_id').serializeObject());
        // data = $('#receiveItems_id').serializeObject();

    $.ajax({
            url: url+'/receives/update',
            type: 'post',
            data: {'items':data, 'action': action},
            dataType: 'json',
            complete: function() {      
                loadingModal('close');
            },
            error: function(result) {

            },
            success: function(result) {

                successAlert('#receiveItems-result', result.message);
            // if (result.success) {

            //      $('input, select, textarea').attr('disabled', true);

            //  } else {
            //      alert(result.message);
            //  }
            }

        });
        console.log(data);
        return false;
}
/**
 * Use to format serialize data and convert to json data
 *
 * Usage: JSON.stringify($('form').serializeObject())
 */
$.fn.serializeObject = function() {
    var o = Object.create(null),
        elementMapper = function(element) {
            element.name = $.camelCase(element.name);
            return element;
        },
        appendToResult = function(i, element) {
            var node = o[element.name];

            if ('undefined' != typeof node && node !== null) {
                o[element.name] = node.push ? node.push(element.value) : [node, element.value];
            } else {
                o[element.name] = element.value;
            }
        };

    $.each($.map(this.serializeArray(), elementMapper), appendToResult);
    console.log(o);
    return o;
};
$.fn.serializeObject = function()
{
    var o = {};
    var a = this.serializeArray();
    $.each(a, function() {
        if (o[this.name] !== undefined) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};