Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter Blog Tutorial difficutlys
#1

[eluser]ohale[/eluser]
i am nearing the end of the tutorial but i need some help?
I Have tryed doing exactly what the tutorial is saying quite sure i am not missing anything. can you guys take a look at my code and tell me what i need to do?

I cant seem to get the comment form to connect with the database. also the submit button dose nothing. hear is all my code. any help would be appreciated.

This is my blog.php

Code:
<?php
class Blog extends CI_Controller {

    


    function index()
    {
        $this->load->helper('url');
        $this->load->helper('form');

        
        $data['title'] = "My blog title";
        $data['heading']= "My blog Heading";
        $data['query'] = $this->db->get('entries');
        
        
        $this->load->view('blog_view', $data);
        
        
    }
    
    function comments()
    {
        $data['title'] = "My comment title";
        $data['heading']= "My commment Heading";
        
        
        $this->load->view('comment_view', $data);
    }

    
}
?>





this is my blog_view.php

Code:
<html>
<head>
<title><?=$title?></title>
</head>
<body>
<h1>&lt;?=$heading?&gt;</h1>


&lt;?php foreach($query->result() as $row): ?&gt;

<h3>&lt;?=$row->title?&gt;</h3>
<p>&lt;?=$row->body?&gt;</p>


<p>&lt;?=anchor('blog/comments/'.$row->id,'Comments');?&gt;</p>

<hr>

&lt;?php endforeach;?&gt;


&lt;/body&gt;
&lt;/html&gt;



this is my comment_view.php
Code:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt;?=$title?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<h1>&lt;?=$heading?&gt;</h1>



<p>&lt;textarea name="body" rows="10"&gt;&lt;/textarea></p>
<p>&lt;input type="text" name="author" /&gt;&lt;/p>
<p>&lt;input type="submit" value="Submit Comment" /&gt;&lt;/p>


&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;



I am useing phpMyAdmin with Mamp
#2

[eluser]toopay[/eluser]
[quote author="ohale" date="1303890286"]I cant seem to get the comment form to connect with the database.[/quote]
First, you must create the database (with user related to that daabase). Then, under 'application/config/' edit database.php with apropriate value, eg :
Code:
$config['hostname'] = "localhost";
$config['username'] = "myusername";
$config['password'] = "mypassword";
$config['database'] = "mydatabase";
$config['dbdriver'] = "mysql";
$config['dbprefix'] = "";
$config['pconnect'] = FALSE;
$config['db_debug'] = TRUE;
then before you can use $this->db...you must load the database
Code:
$this->load->library('database');


[quote author="ohale" date="1303890286"]also the submit button dose nothing...
this is my comment_view.php
Code:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt;?=$title?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<h1>&lt;?=$heading?&gt;</h1>



<p>&lt;textarea name="body" rows="10"&gt;&lt;/textarea></p>
<p>&lt;input type="text" name="author" /&gt;&lt;/p>
<p>&lt;input type="submit" value="Submit Comment" /&gt;&lt;/p>


&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
[/quote]
i'm not see form opening tag there
Code:
&lt;form action="/controllername/function" method="POST"&gt;
...the rest




Theme © iAndrew 2016 - Forum software by © MyBB