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

  • Home
  • SEARCH
  • 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 6116023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:09:31+00:00 2026-05-23T15:09:31+00:00

I have a form that submits data to a database in a CodeIgniter app

  • 0

I have a form that submits data to a database in a CodeIgniter app (CI v. 2.0.2). We are allowing users to “edit” records by having them resubmit a record with new values and then doing an update. On submit, the form calls the vote controller’s create method. Inside the create method, we check to see if there’s already a record based on an entry code and the user’s ID. If there is, we update; otherwise we create a new record. The creation works just fine; it’s only the update I’m having an issue with. Here’s the code.

view

<div id="vote_form">
            <?php
           $hidden = array('dot_judge_id' => $this->session->userdata('dot_judge_id'));

            echo form_open('vote/create'); 
                $entry_code_data = array(
                    'name' => 'entry_code',
                    'id' => 'entry_code',
                    'value' => set_value('entry_code')
                );

                echo form_hidden($hidden);

                $score_options = array('1'=>'1 (lowest)', '2'=>'2','3'=>'3', '4'=>'4','5'=>'5 (highest)');

                ?>
                <p><label for="entry_code">Entry code: </label><?php echo form_input($entry_code_data); ?></p>
                <p><label for="q1">Question 1: </label><?php echo form_dropdown('q1', $score_options, ''); ?></p>
                <p><label for="q2">Question 2: </label><?php echo form_dropdown('q2', $score_options, ''); ?></p>
                <p><label for="q3">Question 3: </label><?php echo form_dropdown('q3', $score_options, ''); ?></p>
                <p><label for="q4">Question 4: </label><?php echo form_dropdown('q4', $score_options, ''); ?></p>
                <p><label for="q5">Question 5: </label><?php echo form_dropdown('q5', $score_options, ''); ?></p>

                <p><?php echo form_submit('submit', 'Submit vote'); ?></p>                

            <?php echo form_close(); ?>
            <?php echo validation_errors(); ?>


        </div>

controller

function create() {
                $id = $this->input->post('entry_code');
                $judge_id = $this->input->post('dot_judge_id');

        $data = array(
            'entry_code' => $id,
            'dot_judge_id' => $judge_id,
            'q1' => $this->input->post('q1'),
                        'q2' => $this->input->post('q2'),
                        'q3' => $this->input->post('q3'),
                        'q4' => $this->input->post('q4'),
                        'q5' => $this->input->post('q5'),

        );

                //first check to see if there's already a record for this judge/entry
                //if so, update. Otherwise, insert
                $vote_id = $this->vote_model->getEntryById($id, $judge_id);
                if($vote_id) {
                        log_message('debug', 'vote id exists: '.$vote_id);
                        $this->vote_model->updateRecord($data, $vote_id);

                }
                else {
                        log_message('debug', 'vote id does not exist; creating new');
                        $this->vote_model->createRecord($data);
                }

                /*
                 after submission, go to another page that gives choices - review entries, submit another entry, log out
                */
                $data['msg'] = "Entry submitted";
        $this->menu();

    }

model

function getEntryByID($id, $judge_id) {
        //determine if record already exists for entry/judge
        $sql = 'SELECT vote_id from dot_vote WHERE entry_code = ? AND dot_judge_id = ?';
        $query = $this->db->query($sql, array($id, $judge_id));

        if($query->num_rows() == 1) {
               $row = $query->row();
               return $row->vote_id;
        }
         else {
            return false;
         }
    }


    function createRecord($data) {
        $this->db->insert('dot_vote', $data);
        return;
    }

    function updateRecord($data, $vote_id) {
        log_message('debug', 'vote id is passed: '.$vote_id);
        $this->db->where('vote_id', $vote_id);
        $this->update('dot_vote', $data);
    }

I know it’s making it into the updateRecord method because the log_message output is in my log file displaying the correct vote_id (the auto-increment field of the returned record). But what I get in the browser is the following:

enter image description here

Can anyone point me in the right direction here? I have error display on in my config file, and have gotten SQL errors when they occur, so I don’t think this is a SQL error. But I have no idea what could be happening in that tiny little function that’s causing this. My next step is to skip the active record update and just use a standard query, but I’d like to know what’s causing the problem here, even if I can get it to work the other way.

  • 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-23T15:09:32+00:00Added an answer on May 23, 2026 at 3:09 pm

    This line stood out:

    $this->update('dot_vote', $data);
    

    Do you mean this?

    $this->db->update('dot_vote', $data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a form that submits data to a database, i have a function
I have a php form that submits data to a database. When the form
i have a PHP contact form that submits data, and an email...: <?php $dbh=mysql_connect
I have a button that I would like to disable when the form submits
I have a form that submits a jQuery .ajax event every time menu's value
I have a form that is trying to insert some data into an SQL
I have a form with a submit button and a handler that stores data
I use a form where i have listed the data from database like title,
I have a modal which pops out a form, allowing an admin to edit/update
I have a form that uses jQuery to submit an ajax post and 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.