1

i have tried to update data of my database, but there is no error this my method

public function update_pj_si(request $request)
{
    $id = $request->id;
    DB::table('tbl_profil_penyedia')
        ->where('id_profil_penyedia', $id)
        ->update(array('status' => 1));
    return redirect('/verif/pj_si');
}

if i run this method, it run correctly and no error but the database is not updated. how can i fix this?

10
  • For one, (request $request) should be (Request $request).. But you say you did not get an error.. that's strange. Is that a typo? Commented Nov 21, 2019 at 8:49
  • 1
    that means the where condition of the query didn't yield any results to update ... the update call should return an integer of the number of records that were affected Commented Nov 21, 2019 at 8:49
  • 2
    May be you required this code in your model protected $fillable = ['status'] Commented Nov 21, 2019 at 9:04
  • yap, there is no error if i run the method, but the data is no update and i have tried to change (request $request) to (Request $request) but the result still same Commented Nov 21, 2019 at 9:08
  • @MuqsithArsyad try to dd(DB::table('tbl_profil_penyedia') ->where('id_profil_penyedia', $id) ->update(array('status' => 1));), if the return is 1, means updated success, if not, means updated failed. And if it is 0 Commented Nov 21, 2019 at 9:13

1 Answer 1

4

The $id variable doesn't contain a value that exists in your table, tbl_profil_penyedia, for the field id_profil_penyedia. It is as simple as that.

You are trying to update a profil_penyedia that doesn't exist.

The update call returning 0, means it didn't update any rows, which means your where condition didn't yield any results to be updated.

Sign up to request clarification or add additional context in comments.

1 Comment

thankyou sir.. before, i have tried input tag table in tag form. so $id cant call and returning 0. after i delete tag table it works. and i want ask again sir.. can the table tag be in the form tag?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.