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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:20:52+00:00 2026-06-12T13:20:52+00:00

Making a form that will accept a bunch of textual data and an image

  • 0

Making a form that will accept a bunch of textual data and an image upload.

Keep getting this error when adding new item to both tables:

Error Number: 1048

Column ‘id_path’ cannot be null

INSERT INTO thumbnails (id_path, id_data_row) VALUES (NULL, 17)

Filename: C:\wamp\www\project\system\database\DB_driver.php

Line Number: 330

What I’m trying to do is add text data(stuff like title, text, price, etc.) into one table(data) and then upload an image and add its full upload path(as primary key in thumbnails table) and the id of the inserted text data row(to link it with the thumbnail in thumbnails table) into thumbnails table.

For some reason it keeps passing NULL as the full upload path to thumbnails table.

crud.php(the controller):

function add()
        {
            //Set validation properties
            $this->_set_fields();

            //Set common properties
            $data['title'] = 'Add new data row';
            $data['message'] = '';
            $data['action'] = site_url('crud/addDataRow');
            $data['link_back'] = anchor('crud/index', 'Back to list', array('class' => 'back'));

            //Load the view
            $this->load->view('templates/header', $data);
            $this->load->view('pages/crud_edit', $data);
            $this->load->view('templates/footer');
        }

        function addDataRow()
        {
            //Set common properties
            $data['title'] = 'Add new data row';
            $data['action'] = site_url('crud/addDataRow');
            $data['link_back'] = anchor('crud/index/', 'Back to list', array('class' => 'back'));

            //Set validation properties
            $this->_set_fields();
            $this->_set_rules();

            //Run validation
            if($this->form_validation->run() == FALSE)
            {
                $data['message'] = '';
            }
            else
            {
                //Save the data
                $full_file_path = null;
                $config['allowed_types'] = 'gif|jpg|png';
                $config['max_size'] = '100';
                $config['max_width']  = '1024';
                $config['max_height']  = '768';
                $path_to_uploads='./uploads';
                $config['upload_path'] = $path_to_uploads;
                $this->load->library('upload', $config);
                //add this
                $this->upload->initialize($config);
                if (!$this->upload->do_upload()){
                    $error = $this->upload->display_errors();
                    echo "<script>alert($error);</script>";
                }else{
                    $upload_data=$this->upload->data();
                    $file_name=$upload_data['file_name'];
                    $full_file_path = $path_to_uploads.'/'.$file_name;
                }


                $data_row = array(
                    'title' => $this->input->post('title'),
                    'text' => $this->input->post('text'),
                    'price' => $this->input->post('price'),
                    'status' => $this->input->post('status'),
                    'type' => $this->input->post('type')
                );

                $id = $this->crud_model->save($data_row);

                $thumbnail_row = array(
                    'id_path' => $full_file_path,
                    'id_data_row' => $id
                );

                $this->crud_model->save_thumbnail($thumbnail_row);

                //Set form input name="id"
                $this->form_validation->id = $id;

                //Set user message
                $data['message'] = '<div class="success">New data row added!</div>';
            }

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

crud_model.php(the model):

//Add new data row
        function save($data)
        {

            $this->db->insert($this->tbl_data, $data);
            return $this->db->insert_id();
        }

        //Add the thumbnail upload path and id of the row in data table to link them
        function save_thumbnail($data)
        {
            $this->db->insert($this->tbl_thumbnails, $data);
            return $this->db->insert_id();
        }

EDIT(html form code):

crud_edit.php(html form code for adding a new item or updating an existing one):

<div id="contentColumn">
    <h1><?php echo $title; ?></h1>
    <?php echo $message; ?>
    <form method="post" action="<?php echo $action; ?>" multipart="multipart">
        <div class="data">
            <table>
                <tr>
                    <td width="30%">ID</td>
                    <td>
                        <input type="text" name="id" disabled="disabled" class="text" value="<?php echo set_value('id'); ?>"/>
                        <input type="hidden" name="id" value="<?php echo set_value('id',$this->form_data->id); ?>"/>
                    </td>
                </tr>
                <tr>
                    <td valign="top">Title<span style="color:red;">*</span></td>
                    <td>
                        <input type="text" name="title" class="text" value="<?php echo set_value('title',$this->form_data->title); ?>"/>
                        <?php echo form_error('title'); ?>
                    </td>
                </tr>
                <tr>
                    <td valign="top">Text<span style="color:red;">*</span></td>
                    <td>
                        <textarea name="text" class="text">
                            <?php echo set_value('text',$this->form_data->text); ?>
                        </textarea>
                        <?php echo form_error('text'); ?>
                    </td>
                </tr>
                <tr>
                    <td valign="top">Price<span style="color:red;">*</span></td>
                    <td>
                        <input type="text" name="price" class="text" value="<?php echo set_value('price',$this->form_data->price); ?>"/>
                        <?php echo form_error('price'); ?>
                    </td>
                </tr>
                <tr>
                    <td valign="top">Thumbnail<span style="color:red;">*</span></td>
                    <td>
                        <?php echo form_upload(array('name'=>'thumb', 'type'=>'file', 'accept'=>'image/*'))?>
                        <!--<input type="file" name="thumb" size="20" />-->
                        <?php echo form_error('thumb'); ?>
                    </td>
                </tr>
                <!--
                <tr>
                    <td valign="top">Images<span style="color:red;">*</span></td>
                    <td>
                        <input type="text" name="images" class="text" value="<?php echo set_value('images',$this->form_data->images); ?>"/>
                        <?php echo form_upload(array('name'=>'images', 'type'=>'file', 'multiple'=>'multiple', 'accept'=>'image/*'))?>
                        <?php echo form_error('images'); ?>
                    </td>
                </tr>
                -->
                <tr>
                    <td valign="top">Status</td>
                    <td>
                        <input type="text" name="status" class="text" value="<?php echo set_value('status',$this->form_data->status); ?>"/>
                        <?php echo form_error('status'); ?>
                    </td>
                </tr>
                <tr>
                    <td valign="top">Type<span style="color:red;">*</span></td>
                    <td>
                        <input type="text" name="type" class="text" value="<?php echo set_value('type',$this->form_data->type); ?>"/>
                        <?php echo form_error('type'); ?>
                    </td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td><input type="submit" value="Save" /></td>
                </tr>
            </table>
        </div>
    </form>
    <br />
    <?php echo $link_back; ?>
</div>
  • 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-12T13:20:53+00:00Added an answer on June 12, 2026 at 1:20 pm

    Change php code as below

    $image1=$this->input->post('thumb');
    if (!$this->upload->do_upload($image1)){
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a contact form that will send an email, but I'm having
Summary I am making a ordering form that will multiply Qty of Items by
I'm making a Windows Form project that will search for files in the specified
I am making app on android that take all data form device and Storage
EDITED: Java httpPost into .asp form I am making an application that will display
I'm making a form that has a checkbox that if checked will slide down
I'm having a little bit of trouble making a sticky form that will remember
I am making a form that builds itself from a given db and table.
I'm making a simple form that is to step through a program iteratively. How
I'm making a fairly simple form with a button that opens a table for

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.