[英]Column not found: 1054 Unknown column '0' in field list
i have 3 forms in one page using ajax
for them. 我在使用ajax
一页中有3种形式。 Edit form is getting error as below. 编辑表单出现如下错误。 I dont know why i am getting this error. 我不知道为什么我收到此错误。 I am beginner . 我是初学者 。 error while submitting form: 提交表单时出错:
"SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'field list' (SQL: update
user_profiles
set0
= ,updated_at
= 2018-08-18 10:25:43 whereid
= 1)" “ SQLSTATE [42S22]:找不到列:1054'字段列表'中的未知列'0'(SQL:更新user_profiles
设置为0
=,updated_at
= 2018-08-18 10:25:43,其中id
= 1)”
This is my edit button code: 这是我的编辑按钮代码:
<a class="btn btn-primary" href="javascript:void(0);" onclick="editExchangeMarket({{$user_profiles->id}});"> <span class="glyphicon glyphicon-edit"></span> Edit </a>
This is my modal and ajax code: 这是我的模态和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">×</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>
Now i am adding here my controller code: 现在我在这里添加我的控制器代码:
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);
}
Update() takes an assocative array to update the values. Update()采用一个关联数组来更新值。 your $data
is already an associative array so no need to push it as an array. 您的$data
已经是一个关联数组,因此无需将其作为数组推送。
$data = array('country_id'=>$country_id,
'id'=>$id,
'charge_per_lot'=>$charge_per_lot,
);
$res = UserProfile::where('id',$id)->update($data)
UserProfile::where('id',$id)->update(
[
'name' => $name,
'number' => $number
]);
by this way you can do query if you have mutiple parameters & values to query 通过这种方式,您可以查询是否有多个参数和值要查询
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.