how to join two table in codeigniter easily[updated] | ci_model | ci_controller | codeigniter 3 -datainflow
Hello guys, this article is for updating a MySQL table row using try catch and with the easiest method. So let’s start.
I have my updating form like this –
<form name="password_update" method="post" action="{{url('update_password')}}"> {{ csrf_field() }} <div class="form-group"> @if(Session::has('pass_error')) <label style="color: red;">{{Session::get('pass_error')}}</label> @else <label>New Password</label> @endif <input required type="text" placeholder="Enter new password" class="form-control" name="new_password"> </div> <div class="form-group"> <input type="submit" value="Save New Password" class="btn btn-success"> </div> </form>
And my update code in controller is like this-
public function update_password(Request $request){ if($request->new_password == ""){ Session::flash('pass_error', 'You cannot submit This form without password'); return redirect('my-profile'); } else{ try{ $PassChange= AdminLogin::findOrFail(session('admin_id')); $PassChange->password = md5($request->new_password); $PassChange->save(); } catch(ModelNotFoundException $err){ //Show error page } Session::flash('pass_success', 'Password Changed Successfully'); return redirect('my-profile'); } }
That’s all. You try yourself and if you stuck in any error you can comment here…
Related posts
I аm regular reader, how are youu everybody? This post posted at thіs website is genuinelу fastidious.
We are trying to make better post. Thanks for your comment here.