database - Displaying form data with php and laravel -
hi there trying form data stored in database , show data object on webpage. wanting able edit object's data , update database new information.
like comments/post section on blog/facebook
thanks can offer specifics/ have below. using laravel 4.2 , sqlite manage everything. think issue routes though.
have great day.
this directory layout
- app -- database ---posts.sql ---comments.sql -- views --- layouts ------- default.blade.php --- pages ------- home.blade.php ------- edit.blade.php --- includes ------- head.blade.php ------- header.blade.php ------- footer.blade.php --routes.php
i have 2 databases trying interact add/edit/delete rows.
both follow format
/* posts database in sqlite. */ drop table if exists posts; create table posts ( id integer primary key autoincrement, number int, /* 0 = subsequent term */ post_username varchar(40) not null, post_title varchar(40), post varchar(140) ); /* column names changed avoid sqlite reserved words. */ insert posts(number, post_username, post_title, post) values (1,'first poster', 'first title', 'first'); insert posts(number, post_username, post_title, post) values (2,'second poster', 'second title', 'second post'); /* sample query test insertion worked. */ select * posts post_title "%first%" order id;
and want able display current information in .sql file(s) on home page using tables whilst adding page new form.
@section('title') home page @stop @extends('layouts.default') @section('content') <form class="form-horizontal"> <fieldset> <!-- form name --> <form method="get" action="add_post"> <table> <tr><td>post username: </td><td><input type="text" name="post_username"></td></tr> <tr><td>post title: </td><td><input type="text" name="post_title"></td></tr> <tr><td>post: </td><td><input type="text" name="post"></td></tr> <tr><td colspan=2><input type="submit" value="add_post"> <input type="reset" value="reset"></td></tr> <table> </form> @if (count($posts) == 0) <p>no current posts</p> <table class="bordered"> <thead> <tr><th>no.</th><th>post username</th><th>post title</th><th>post</th></tr> </thead> <tbody> @foreach($posts $post) <tr><td>{{{ $post->number }}}</td><td>{{{ $post->post_username }}}</td><td>{{{ $post->post_title }}}</td><td>{{{ $post->post }}}</td></tr> @endforeach @stop
but doesn't work don't know why.
please multimedia nerd picked web-programming course , realizing mistake :)
routes page:
<?php $post_username = input::get('post_username'); $post_title = input::get('post_title'); $post = input::get('post'); route::get('/', function() { return view::make('pages.home'); }); route::get('/comments', function() { return view::make('pages.comments'); }); /* crashing website route::get('add_post', function() { $sql = "insert posts (post_username, post_title, post) values (?, ?, ?)"; db::insert($sql, array($post_username, $post_title, $post)); }); */
change routes this:
<?php route::get('/', function() { return view::make('pages.home'); }); route::get('/comments', function() { return view::make('pages.comments'); }); // crashing website route::get('add_post', function() { $post_username = input::get('post_username'); $post_title = input::get('post_title'); $post = input::get('post'); $sql = "insert posts (post_username, post_title, post) values (?, ?, ?)"; db::insert($sql, array($post_username, $post_title, $post)); });
and, instead of doing save logic inside route should write in controller. there tutorial laracast , culttt, kindly visit them , change approach. see, if helps.
Comments
Post a Comment