mercredi 15 avril 2015

Laravel Database Update using Form

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

Aucun commentaire:

Enregistrer un commentaire