Fadee
Fadee

Reputation: 101

Laravel - PDO - UPDATING

Alright , a PDO code when I run in my localhost works perfect , but when I run in my host doesnt work and gives me an error which is

QueryException in Connection.php line 651: SQLSTATE[HY000]: General error: 2053 (SQL: UPDATE roles SET member_id=76446,member_role=5613 WHERE member_id=76446)

the code is

if (!empty($member->id)) {



        $new_id = $member->id;

        $new_p = $member->p_id;

        $sql = "UPDATE roles SET member_id=$new_id,member_role=$new_p WHERE member_id=$new_id";

        $member = DB::select($sql);

        Session::flash('sm', 'Thank you! You have edited the Profile successfully!');

    }

I appreciate help !

Upvotes: 1

Views: 642

Answers (1)

Gal Sisso
Gal Sisso

Reputation: 1959

Laravel got built in query builder so your code should look like -

if (!empty($member->id)) {

        $new_id = $member->id;

        $new_p = $member->p_id;

        DB::table('roles')->where('member_id', $new_id)->update(['member_role' => $new_p]);

        Session::flash('sm', 'Thank you! You have edited the Profile successfully!');

    }

I removed the member_id=$new_id as you already check this part in the where clause

Upvotes: 0

Related Questions