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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:13:52+00:00 2026-05-25T06:13:52+00:00

I may well be missing something quite obvious, but I’m still a bit lost.

  • 0

I may well be missing something quite obvious, but I’m still a bit lost. The actual database interaction seems to be the catch. I mean, the table is created on installation, but actually sending the information doesn’t seem to work as it triggers the validation regardless of what I enter. If I turn off the field requirements, the database fails to receive the information entirely.

From the controller:

class Admin extends Admin_Controller
{

private $show_validation_rules = array(
    array(
        'field' => 'date',
        'label' => 'Date',
        'rules' => 'trim|max_length[100]|required'
    ),
    array(
        'field' => 'location',
        'label' => 'Location',
        'rules' => 'trim|max_length[300]'
    ),
    array(
        'field' => 'support',
        'label' => 'Support',
        'rules' => 'trim|required'
    )

);

public function __construct()
{
    parent::__construct();

    $this->load->model('shows_m');
    $this->load->library('form_validation');
    $this->lang->load('shows');
    $this->load->helper('html');

    $this->template->set_partial('shortcuts', 'admin/partials/shortcuts');
}

public function index()
{
    $view_data = array();
    $view_data['shows'] = $this->shows_m->get_all();
    $this->template->build('admin/index', $view_data);
}

public function create()
{

    $shows = $this->shows_m->get_all();

    $this->form_validation->set_rules($this->show_validation_rules);

    if ( $this->form_validation->run() )
    {
        if ($this->shows_m->insert_show($this->input->post()))
        {
            $this->session->set_flashdata('success', lang('shows.create_success'));
            redirect('admin/shows/index');
        } else {
            $this->session->set_flashdata('error', lang('shows.create_error'));
            redirect('admin/shows/create');
        }
    }

    foreach($this->show_validation_rules as $rule)
    {
        $shows[$rule['field']] = $this->input->post($rule['field']);
    }
    $view_data = array(
            'shows' => $shows
        );
    $this->template->build('admin/create', $view_data);
}

public function edit($id)
{
    $this->form_validation->set_rules($this->show_validation_rules);

    $show = $this->shows_m->get($id);

    if ( empty($show) )
    {
        $this->session->set_flashdata('error', lang('shows.exists_error'));
        redirect('admin/shows');
    }

    if ( $this->form_validation->run() )
    {

        if ( $this->shows_m->update_entry($id, $this->input->post()) === TRUE )
        {
            if ( isset($this->input->post()['delete']) )
            {
                $this->session->set_flashdata('success', lang('shows.delete_success'));
                redirect('admin/shows/');
            }
            else
            {
                $this->session->set_flashdata('success', lang('shows.update_success'));
                redirect('admin/shows/edit/' . $id);
            }
        } else {
            if ( isset($this->input->post()['delete']) )
            {
                $this->session->set_flashdata('error', lang('shows.delete_error'));
                redirect('admin/shows/edit/' . $id);
            }
            else
            {
                $this->session->set_flashdata('error', lang('shows.update_error'));
                redirect('admin/shows/edit/' . $id);
            }
        }
    }

    foreach($this->show_validation_rules as $rule)
    {
        if ($this->input->post($rule['field']))
        {   
            $show[$rule['field']] = $this->input->post($rule['field']);
        }
    }
    $view_data = array(
            'shows' => $show
        );
    $this->template->build('admin/edit', $view_data);
}

public function delete($id = NULL)
{
    $id_array = array();

    if ( $this->input->post() )
    {
        $id_array = $this->input->post()['action_to'];
    }
    else
    {
        if ( $id !== NULL )
        {
            $id_array[0] = $id;
        }
    }

    if ( empty($id_array) )
    {
        $this->session->set_flashdata('error', lang('shows.id_error'));
        redirect('admin/shows');
    }

    foreach ( $id_array as $id)
    {

        $show = $this->shows_m->get($id);

        if ( !empty($show) )
        {

            if ( $this->shows_m->delete($id) == FALSE )
            {
                $this->session->set_flashdata('error', lang('shows.delete_error'));
                redirect('admin/shows');
            }
        }
    }

    $this->session->set_flashdata('success', lang('shows.delete_success'));
    redirect('admin/shows');
}

}

From the details.php file

public function install()
{
    $this->dbforge->drop_table('shows');
    $shows = "
        CREATE TABLE ".$this->db->dbprefix('shows')." (
          `id` int(11) NOT NULL AUTO_INCREMENT,
          `date` varchar(100) NOT NULL,
          `location` varchar(300) NOT NULL,
          `support` text,
          PRIMARY KEY (`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    ";

    if($this->db->query($shows))
    {
        return TRUE;
    }
}

The intent of the module is, in short to output the date of the show, the location and any supporting bands and other info by inserting a tag produced by the module in to the pertinent page on the site.

I’m inclined to think it should be quite simple and that I’m missing something obvious, but who knows. If I am, feel free to yell at me, I’d appreciate it.

Edit:

Code for the model

class Shows_m extends MY_Model {

public function get_all($limit = NULL)
{
    $this->db->order_by("id", "desc");
    if (isset($limit)){ $this->db->limit($limit); }
    $results = $this->db->get('shows');
    $result = $results->result_array();
    return $result;
}


public function get($id)
{
    $results = $this->db->get_where('shows', array('id' => $id));
    $result = $results->row_array();
    return $result;
}


public function insert_show($input)
{

    $to_insert = array(
        'date' => $input['date'],
        'location' => $input['location'],
        'support' => $input['support']
    );


    if ($this->db->insert('shows',$to_insert))
    {
        return TRUE;
    } else {
        return FALSE;
    }
}


public function update_entry($id, $input)
{
    $new_data = array(
        'date' => $input['date'],
        'location' => $input['location'],
        'support' => $input['support']
    );

    if (isset ($input['delete']) )
    {
        if($this->delete($id))
        {
            return TRUE;
        } else {
            return FALSE;
        }
    } else {

        $this->db->where('id', $id);
        if ($this->db->update('shows', $new_data))
        {
            return TRUE;    
        } else {
            return FALSE;    
        }
    }
}


public function delete($id)
{
    if ($this->db->delete('shows', array('id' => $id)))
    {
        return TRUE;    
    } else {
        return FALSE;    
    }
}
}
  • 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-25T06:13:52+00:00Added an answer on May 25, 2026 at 6:13 am

    It might be your insert in the model

    if ($this->db->insert('shows',$to_insert))
        {
            return TRUE;
        } else {
            return FALSE;
        }
    

    Try instead:

    $this->db->insert('shows',$to_insert);
    $query_result = $this->db->insert_id();
    if($query_result){
        return TRUE;
    }else{
        return FALSE;
    }
    

    I don’t think insert returns anything.

    At any rate, it doesn’t sound like validation is the problem. The query isn’t getting to the db. If the above isn’t the issue, try just echoing out the POST data; make sure it’s getting to the model (make sure the HTML is as expected–input names and such).

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

Sidebar

Related Questions

I may well be missing something here but I'm noticing very slow performance when
I'm may be missing something but I can't find the Delphi 2007 WSDL Importer
I'm a newbie with Jquery, so I may be missing something obvious... . I
This may well be simple, but I'm new to Drupal. The organization I work
I know this question may well be the silliest question you've heard today, but
Ok, I may be in well over my head here, but suspect I am
Well, I'm learning Scala so this question may be too basic for most people.
You may know the scriptaculous SlideUp effect . Well, It slides up a div
I have this linq query that works well (although it may be written better,
May be I am getting old, but I can't find it...

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.