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 9088929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:01:10+00:00 2026-06-16T22:01:10+00:00

I just started using CodeIgniter today, and was following the tutorial at the CI

  • 0

I just started using CodeIgniter today, and was following the tutorial at the CI website.

When I got to the final step for creating a new news item, I ran into an issue with the form submit. I would expect the URL to be jonhopkins.net/news/create when I press the form’s submit button, but it is going to http://jonhopkins.net/news/jonhopkins.net/news/create instead, which is clearly very wrong, and I have no idea why this is happening. Does anyone know how to fix this?

Everything else on my site (the Pages part of the tutorial) works perfectly. This is the only thing that is breaking. All of my code is exactly as it appears in the tutorial, except for a change to what happens when an item is successfully submitted to the database, which currently is never happening.

News Controller

public function create() {
    $this->load->helper('form');
    $this->load->library('form_validation');

    $data['title'] = 'Create a news item';

    $this->form_validation->set_rules('title', 'Title', 'required');
    $this->form_validation->set_rules('text', 'text', 'required');

    if ($this->form_validation->run() === FALSE) {
        $this->load->view('templates/header', $data);
        $this->load->view('news/create');
        $this->load->view('templates/footer');
    } else {
        //$success will contain the slug of the created item, or FALSE if database insertion failed
        $success = $this->news_model->set_news();
        if ($success) {
            $this->_doView($success);
        } else {
            echo "Something went wrong while trying to submit the news item.";
        }
    }
}

public function view($slug) {
    $this->_doView($slug);
}

private function _doView($slug) {
    $data['news_item'] = $this->news_model->get_news($slug);
    if (empty($data['news_item'])) {
        show_404();
    }

    $data['title'] = $data['news_item']['title'];

    $this->load->view('templates/header', $data);
    $this->load->view('news/view', $data);
    $this->load->view('templates/footer');
}

Create View

<h2>Create a news item</h2>

<?php echo validation_errors(); ?>
<?php echo form_open('news/create') ?>
    <label for="title">Title</label> 
    <input type="input" name="title" /><br />

    <label for="text">Text</label>
    <textarea name="text"></textarea><br />

    <input type="submit" name="submit" value="Create news item" /> 
</form>

And the resulting HTML…

<form action="jonhopkins.net/news/create" method="post" accept-charset="utf-8"> 
    <label for="title">Title</label> 
    <input type="input" name="title" /><br />

    <label for="text">Text</label>
    <textarea name="text"></textarea><br />

    <input type="submit" name="submit" value="Create news item" /> 
</form>

News Model I don’t think it’s ever getting here, but just in case

public function set_news() {
    $this->load->helper('url');

    $slug = url_title($this->input->post('title'), 'dash', TRUE);

    $data = array(
        'title' => $this->input->post('title'),
        'slug' => $slug,
        'text' => $this->input->post('text'),
        'date' => date("Y-m-d H:i:s")
    );

    if ($this->db->insert('news', $data)) {
        return $slug;
    } else {
        return FALSE;
    }
}

Routes

$route['news/create'] = 'news/create';
$route['news/(:any)'] = 'news/view/$1';
$route['news'] = 'news';
$route['(:any)'] = 'pages/view/$1';
$route['default_controller'] = 'pages/view';
  • 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-06-16T22:01:11+00:00Added an answer on June 16, 2026 at 10:01 pm

    The form_open('news/create') method uses the $CI->Config->site_url() method which, in turn, uses the base_url from your config file.

    Make sure your $config['base_url'] is set to your domain (with trailing slash) in the application/config/config.php file.

    $config['base_url'] = 'http://jonhopkins.net/';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started using CodeIgniter after using Zend for a while. My new site
just started using JPA today, so i'm preety new to it. How would one
I just started using the new Eclipse 4.2 (Juno) Null Analysis. On code like
I just started using Laravel. When I use codeigniter or zend framework, I can
I've just started to use codeigniter and I have a question. I am using
Just started using CodeIgniter, loving it. Having enabled the database to be one of
I just started using the document class in flash cs6 today... so I learned
I've just started using codeigniter and wanted to include some external css in my
I just started using OOP / CodeIgniter. I want to get assign the form
Just started using Xcode 4.5 and I got this error in the console: Warning:

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.