1

Im trying to update my sqlite database using a form. I first retrieve the contents of the table row and display it in a form, i can then edit the contents of the form and when im done press update, which should update the table and redirect to 'home' but instead i receive this error:

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException

for what reason am i receiving this message?

Heres the code thats executing:

function updateStatus(){
    $id = Input::get('id');
    $uptitle = Input::get('title');
    $upmessage = Input::get('message');


    $sql = "UPDATE status SET title= ? Message= ? WHERE Id= ?";
    DB::update($sql, array($uptitle, $upmessage, $id));
}

Routes:

Route::post('updated',function()
{
    updateStatus();

    $results = getPosts();

    return Redirect::to('home')->withPosts($results);
});



function getPosts()
{
    $sql = "select * from status order by Id DESC";
    $results = DB::select($sql);
    return $results;
}

The form that executes the route "update":

@section('content')
@forelse ($edits as $edit)
<form method="post" action="updated" >
      <div class="form-group">
          <input type="hidden" name="id" value="{{{ $edit->Id }}}"> 
         <!-- <label>Name</label>
                <input name ="name" class="form-control" value='{{{ $edit->Name }}}'>
          -->
            <label>Post Title</label>
                <input name ="title" class="form-control"  value='{{{ $edit->Title }}}'>
      </div>
      <div class="form-group">
            <label>Message</label>
            <textarea class="form-control" name="message"  rows="3" >{{{ $edit->Message }}}</textarea>
      </div>


    <button type="update" class="btn btn-default">Update</button>
</form>
@empty
     No Posts
    @endforelse
@stop
1
  • Add / inside action attribute before updated <form method="post" action="/updated" > Commented Apr 16, 2015 at 7:27

1 Answer 1

2

I think you can't run the function updateStatus like this..

First create an controller StatusController. Then you do it like this:

public function index() {
   $sql = "select * from status order by Id DESC";
   $results = DB::select($sql);
   return $results;
}

public function edit($id) {
   // Get the status
   $edit = Status::find($id);
   // Here return your edit page for updating the status
   return View::make('status.edit', array('edit' => $edit));
}

public function updateStatus($id) {
   // Get the status
   $status = Status::find($id);

   $uptitle = Input::get('title');
   $upmessage = Input::get('message');

   $sql = "UPDATE status SET title= ? Message= ? WHERE Id= ?";
   DB::update($sql, array($uptitle, $upmessage, $status->id));

   return Redirect::to('home');
}

Routes

Route::get('statuses', 'StatusController@index');
Route::get('statuses/edit/{id}', 'StatusController@edit');
Route::post('statuses/edit/{id}', 'StatusController@updateStatus');
Sign up to request clarification or add additional context in comments.

Comments

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.