HI there I am trying to get form data to be stored in a database and then show that data as an object on the webpage. I am then wanting to be able to edit that object's data and update the database with the new information.
Like a comments/post section on a blog/facebook
Thanks for any help you can offer the specifics/ what i currently have is below. I am using laravel 4.2 and sqlite to manage everything. I think the issue is with my routes though.
Have a great day.
This is my 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 currently have two databases that I am trying to interact with add/edit/delete rows.
Both follow this 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 to avoid SQLite reserved words. */
insert into posts(number, post_username, post_title, post) values (1,'First Poster', 'first title', 'first');
insert into posts(number, post_username, post_title, post) values (2,'Second Poster', 'second title', 'second post');
/* Sample query to test insertion worked. */
select * from posts
where post_title like "%first%"
order by id;
And I want to be able to display current information in the .sql file(s) on the home page using tables like so whilst also adding to the page with a 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 as $post)
<tr><td>{{{ $post->number }}}</td><td>{{{ $post->post_username }}}</td><td>{{{ $post->post_title }}}</td><td>{{{ $post->post }}}</td></tr>
@endforeach
@stop
But it doesn't work I don't know why.
Please help multimedia nerd who picked up a web-programming course and is just realizing the 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');
});
/*
Currently crashing website
Route::get('add_post', function()
{
$sql = "insert into posts (post_username, post_title, post) values (?, ?, ?)";
DB::insert($sql, array($post_username, $post_title, $post));
});
*/
Aucun commentaire:
Enregistrer un commentaire