Reputation: 181
i have 3 forms in one page using ajax
for them. 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)"
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:
<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);
}
Upvotes: 1
Views: 2523
Reputation: 1066
UserProfile::where('id',$id)->update(
[
'name' => $name,
'number' => $number
]);
by this way you can do query if you have mutiple parameters & values to query
Upvotes: 0
Reputation: 15971
Update() takes an assocative array to update the values. your $data
is already an associative array so no need to push it as an array.
$data = array('country_id'=>$country_id,
'id'=>$id,
'charge_per_lot'=>$charge_per_lot,
);
$res = UserProfile::where('id',$id)->update($data)
Upvotes: 3