gpt4 book ai didi

php - 错误 SQLSTATE[42000] Laravel 更新

转载 作者:行者123 更新时间:2023-11-29 20:53:47 25 4
gpt4 key购买 nike

我有一个应用程序想要更新数据,但是当我想要更新数据而不进行更改时,我发现系统中出现错误。但如果我更改了其中一项数据,我的更新就会成功。

这是我的 Controller :

public function getDetails($id)  {
$data['row'] = data_kos::find($id);

return view('details_add',$data);
}

public function postDetailsSave($id) {
$simpan= array();
if (Request::hasfile('photo1')) {
$destinationPath = 'uploads'; // upload path
$extension = Request::file('photo1')->getClientOriginalExtension(); // getting image extension
$fileName = rand(11111,99999).'.'.$extension; // renameing image
Request::file('photo1')->move($destinationPath, $fileName); // uploading file to given path
$simpan['photo1']=$fileName;
}
if (Request::hasfile('photo2')) {
$destinationPath1 = 'uploads'; // upload path
$extension1 = Request::file('photo2')->getClientOriginalExtension(); // getting image extension
$fileName1 = rand(11111,99999).'.'.$extension1; // renameing image
Request::file('photo2')->move($destinationPath1, $fileName1); // uploading file to given path
$simpan['photo2']=$fileName1;
}
if (Request::hasfile('photo3')) {
$destinationPath2 = 'uploads'; // upload path
$extension2 = Request::file('photo3')->getClientOriginalExtension(); // getting image extension
$fileName2 = rand(11111,99999).'.'.$extension2; // renameing image
Request::file('photo3')->move($destinationPath2, $fileName2); // uploading file to given path
$simpan['photo3']=$fileName2;
}
if (Request::hasfile('photo4')) {
$destinationPath3 = 'uploads'; // upload path
$extension3 = Request::file('photo4')->getClientOriginalExtension(); // getting image extension
$fileName3 = rand(11111,99999).'.'.$extension3; // renameing image
Request::file('photo4')->move($destinationPath3, $fileName3); // uploading file to given path
$simpan['photo4']=$fileName3;
}
if (Request::hasfile('photo5')) {
$destinationPath4 = 'uploads'; // upload path
$extension4 = Request::file('photo5')->getClientOriginalExtension(); // getting image extension
$fileName4 = rand(11111,99999).'.'.$extension4; // renameing image
Request::file('photo5')->move($destinationPath4, $fileName4); // uploading file to given path
$simpan['photo5']=$fileName4;
}

DB::table('data_kos')->where('id', $id)->update($simpan);
Session::flash('edit', 'Data successfully edited');
return Redirect::to('home');
}

这是我的观点:

<form method='post' action='{{action("KostController@postDetailsSave")."/$row->id" }}' enctype="multipart/form-data">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="box-body">
<div class="box-body">
<div class='form-group col-sm-12'>
<label>Title</label>
<input type='text' class='form-control' name='title' value='{{ @$row->title }}' readonly />
</div>
<div class='form-group col-sm-4'>
<label>gambar</label><br>
<img src="../../uploads/{{ $row->photo1 }}" height="70px">
<input type='file' class='form-control' name='photo1' value='{{ @$row->photo1 }}'/>
</div><br>
<div class='form-group col-sm-4'>
<label>gambar</label><br>
<img src="../../uploads/{{ $row->photo2 }}" height="70px">
<input type='file' class='form-control' name='photo2' value='{{ @$row->photo2 }}'/>
</div>
<div class='form-group col-sm-4'>
<label>gambar</label><br>
<img src="../../uploads/{{ $row->photo3 }}" height="70px">
<input type='file' class='form-control' name='photo3' value='{{ @$row->photo3 }}'/>
</div>
<div class='form-group col-sm-4'>
<label>gambar</label><br>
<img src="../../uploads/{{ $row->photo4 }}" height="70px">
<input type='file' class='form-control' name='photo4' value='{{ @$row->photo4 }}'/>
</div>
<div class='form-group col-sm-4'>
<label>gambar</label><br>
<img src="../../uploads/{{ $row->photo5 }}" height="70px">
<input type='file' class='form-control' name='photo5' value='{{ @$row->photo5 }}'/>
</div>

<div class='form-group col-sm-12'>
<button type='submit' class='btn btn-primary'><i class='fa fa-save'></i> Simpan</button>
</div>
</div><!-- /.box -->
</form>

这是我的 table this my table 任何人都可以给我解决方案吗?对于我的问题

这是我的错误 here my error

最佳答案

从错误消息来看,您面临的问题是 $simpan 为空。也许在尝试更新数据库之前 dd() 该变量的内容,看看是否是这种情况......

关于php - 错误 SQLSTATE[42000] Laravel 更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37802789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com