Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7611655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:42:57+00:00 2026-05-31T01:42:57+00:00

After completing the tutorial from the codeigniter user guide I ran into a problem

  • 0

After completing the tutorial from the codeigniter user guide I ran into a problem I was forcing for the last two hours. I am trying to add functionality to delete a post, selected by ID, I am new to PHP and couldn’t find any solution for my problem:

The Controller

public function delete($id){
    $id = $this->uri->segment(3);

    $data['title'] = 'Delete an item';

    if($this->news_model->delete_news($id)){
        $this->load->view('templates/header', $data);  
        $this->load->view('news/success');
        $this->load->view('templates/footer');
    }else{
    }
}

The Model

  public function delete_news($id){
        $this->db->where('id',$id)->delete('news');

        return $this->db->affected_rows();
    }

The Routing

   $route['news/delete/(:num)'] = 'news/delete/$1';

I’m calling the function out of the index-page where all posts are shown with an anchor:

<p><a href="<?php echo site_url('news/delete/'.$news_item['id'])?>">Delete article</a></p>

and it calls the correct URL (http://localhost/webapp/index.php/news/delete/2) which should correctly execute and delete the post with the ID 2 from my news table.

I really can’t understand where the mistake ism but by executing this, I get a 404.
What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:42:58+00:00Added an answer on May 31, 2026 at 1:42 am

    In your function delete I don’t see that you loaded the news_model. That could be the issue if it isn’t auto-loading. Perhaps, start by verifying that the controller is talking to the model by inserting:

    echo 'Hello Model';
    

    in the delete_news function of your news_model.

    EDIT:

    Instead of

      if($this->news_model->delete_news($id)){ 
         //conditions
      }
    

    And

    Have your model send a T/F based on it’s execution. This will tell us if the error is in the SQL. By returning TRUE no matter what, we’ll see if that model function even runs:

     return TRUE;
    

    Try to add the step (for error checking)

    $del = $this->news_model->delete_news($id);
    echo 'del';
    if($del == TRUE){
       //conditions
    }
    

    With the 404 – I’m also suspicious it’s a routing issue. I’ll take a look at that as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Do the international students get a job offer in Australia after completing their Masters degree from University of Melbourne?
I am following through this tutorial and after completing it I am getting an
I'm trying to get a CSS animation property to stay after completing, is this
For some reason, after a user enters text into an EditText within my Android
I have recently started working on a very large C++ project that, after completing
After hours of debugging, it appears to me that in FireFox, the innerHTML of
I've 6 different type of List results after completing AsyncTask . And the List
The problem is to search a password into a big file of size about
I am completing a tutorial which can be found here...http://www.elated.com/articles/cms-in-an-afternoon-php-mysql/ I am having problems
enter code hereI'm trying to finish up Michael Hartl's Ruby on Rails v3.2 Tutorial

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.