0

I keep receiving this error message when I try to open a specific blog in a post I'm making. Its been about 3 days and I've gone over the code countless times. Im using CodeIgnigter and I've followed everything very carefully, the blog connects to the database and displays fine on the php_index page, but crashes when I try to open a specific post or edit, and also comes up with the error "You don't have permission to access /blog/CodeIgniter_2.2.0/< on this server." if i try to use my delete function. My code is shown below.

In my controller folder

<?php

class Posts extends CI_Controller{

function __construct(){
    parent::__construct();
    $this->load->model('post');
}

function index(){
    $data['posts']=$this->post->get_posts();
    $this->load->view('post_index',$data);
}

function post($postID){
    $data['post']=$this->post->get_post($postID);
    $this->load->view('post',$data);
}

function new_post(){
    if($_POST){
        $data=array(
            'title'=>$_POST['title'],
            'post'=>$_POST['post'],
            'active'=>1
        );
        $this->post->insert_post($data);
        redirect(base_url().'posts/');
    } else {
        $this->load->view('new_post');
    }
}

function editpost($postID){
    $data['success']=0;
    if($_POST){
            $data_post=array(
                'title'=>$_POST['title'],
                'post'=>$_POST['post'],
                'active'=>1
        );
        $this->post->update_post($postID, $data);
        $data['success']=1;
    }
    $data['post']=$this->post->get_post($postID);
    $this->load->view('edit_post',$data);
}

function deletepost(){
    $this->post->delete_post($postID);
    redirect(base_url());
}}?>

and then my views folder

For singular post:

<!DOCTYPE HTML>
<html>
<head>
</head>
<body>

    <?php if(!isset($post)){ ?>
    <p>This Page Was Accessed Incorrectly</p>
    <? } else { ?>
    <h2><?=$post['title']?></h2>
    <?=$post['post']?>
    <? } ?>
</body>
</html>

My Model folder

<?php
    class Post extends CI_Model{
        function get_posts($num=20, $start=0){
            $this->db->select()->from('posts')->where('active', 1)->order_by('date_added','desc')->limit($num, $start);
            $query=$this->db->get();
            return $query->result_array();
        }

        function get_post($postID){
            $this->db->select()->from('posts')->where(array('active'=>1, 'postID'=>$postID))->order_by('date_added','desc');
            $query=$this->db->get();
            return $query->first_row('array');
        }

        function insert_post($data){
            $this->db->insert('posts',$data);
            return $this->db->insert_id();

        }

        function update_post($postID,$data){
            $this->db->where('postID',$postID);
            $this->db->update('posts',$data);
        }

        function delete_post($postID,$data){
            $this->db->where('postID',$postID);
            $this->db->delete('posts');
        }
    }
?>
user3019749
  • 81
  • 1
  • 3
  • 9

1 Answers1

0

Do you have a .htaccess file in place? If not, try to put this one in your document root:

https://gist.github.com/philipptempel/4226750

Make sure to set the rewrite base in .htaccess to your CodeIgniter install folder, I think it's /blog/CodeIgniter_2.2.0/ in your case. The .htaccess should be in the same folder as your index.php.

If you also want to remove the index.php part from your url have a look here: CodeIgniter removing index.php from url

Community
  • 1
  • 1
  • Yeha I do have a .htaccess in place but its still not working RewriteEngine on RewriteCond $1 !^(index\.php|images|robots\.txt) RewriteRule ^(.*)$ index.php/$1 [L] – user3019749 Jun 16 '14 at 10:17