2016-06-14 14 views
0

Ich habe eine Anwendung Ich möchte Update-Daten machen, aber ich finde einen Fehler in meinem System, wenn ich die Daten ohne Änderung aktualisieren möchten. aber wenn ich eines der daten geändert habe, ist mein update erfolgreich.Fehler SQLSTATE [42000] Laravel Update

hier mein 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'); 
    } 

und hier meine Ansicht:

<form method='post' action='{{action("[email protected]")."/$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> 

hier meinen Tisch this my table kann mir jemand lösung geben? für mein Problem

und hier mein Fehler here my error

Antwort

0

Es sieht aus der Fehlermeldung, die das Problem Sie konfrontiert sind, ist, dass $simpan leer ist. Vielleicht dd() den Inhalt dieser Variablen vor dem Versuch, die DB zu aktualisieren, um zu sehen, ob das der Fall sein könnte ...

+0

kann, können Sie mir einen Tipp geben, wie man es benutzt? –

+0

setzen Sie diese Zeile 'dd ($ simpan);' direkt vor dieser Zeile 'DB :: table ('data_kos') -> wo ('id', $ id) -> update ($ simpan);' und es wird angezeigt Sie, welche Daten die Variable enthält. – IzzEps

+0

ahh ich sehe, aber seine einzige Show '[]' –

Verwandte Themen