找不到列:1054字段列表中的未知列'0'

时间:2018-08-18 10:40:46

标签: html laravel laravel-5

我在一页中使用ajax使用3种形式。编辑表单出现如下错误。我不知道为什么我收到此错误。 我是初学者。 提交表单时出错:

  

“ SQLSTATE [42S22]:找不到列:1054'字段列表'中的未知列'0'(SQL:更新user_profiles设置0 =,updated_at = 2018-08 -18 10:25:43其中id = 1)“

这是我的修改按钮代码:

<a class="btn btn-primary" href="javascript:void(0);" onclick="editExchangeMarket({{$user_profiles->id}});">
    <span class="glyphicon glyphicon-edit"></span> Edit
</a>

这是我的模态和ajax代码:

<script>
        function updateExchangeMarket() {
            var edit_fid = $('#edit_fid').val();
            var edit_charge_per_lot = $('#edit_charge_per_lot').val();
            $('#exchangeMarketModal').modal('show');
            //   alert(values);
            $.ajax({
                headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
                url: "{{URL::to('user/updateExchangeMarket')}}",
                data:{'id' : edit_fid, 'edit_charge_per_lot':edit_charge_per_lot},
                method:'POST',
                success: function( resp ) {
                    },
                error: function( req, status, err ) {
                console.log( 'something went wrong', status, err );
                    }
            });

        }
</script>
<div id="exchangeMarketModal" class="modal fade" role="dialog">
    <div class="modal-dialog">
        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Modal Header</h4>
            </div>
            <div class="modal-body">
                <form id="exchangeMarketForm" name="exchangeMarketForm" >
                    <input type="hidden" class="form-control" id="edit_fid" value="1">

                    <div class="col-md-6 mb-3 form-group">
                        chargeperlot: <input type="text" name="edit_charge_per_lot" id="edit_charge_per_lot" class="form-control"><br>
                    </div>
               
                </form>
            </div>
            <div class="modal-footer">

                <a type="submit" href="javascript:void(1);" onclick="updateExchangeMarket({{$user_profiles->id}});" value="Submit" class="btn btn-primary">Save changes</a>
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>

    </div>
</div>

现在我在这里添加我的控制器代码:

        public function updateExchangeMarket(Request $request)
    {
        $id = $request->id;    
        $charge_per_lot = $request->edit_charge_per_lot;

        $data = array('country_id'=>$country_id,
            'id'=>$id,
            'charge_per_lot'=>$charge_per_lot,

        );
        $res = UserProfile::where('id',$id)->update([$data]);
        echo json_encode($res);
    }

2 个答案:

答案 0 :(得分:2)

Update()采用一个关联数组来更新值。您的$data已经是一个关联数组,因此无需将其作为数组推送。

$data = array('country_id'=>$country_id,
            'id'=>$id,
            'charge_per_lot'=>$charge_per_lot,

        );
        $res = UserProfile::where('id',$id)->update($data)

答案 1 :(得分:0)

UserProfile::where('id',$id)->update(
[
  'name' => $name,
  'number' => $number
]);

通过这种方式,您可以查询是否有多个要查询的参数和值