Welcome Guest, Not a member yet? Register   Sign In
Cant figure out why my database isnt updating...
#1

(This post was last modified: 05-05-2015, 12:02 PM by alexandervj.)

I'm a noob, I cant figure out why my database isnt updating. Here is my view...

Code:
<?php echo form_open('dev_database/update_part/'.$l->lotID.'/'.$r->runID.'/'.$p->partID.''); ?>

<input type="submit" class="btn btn-success btn-sm" value='Save'>
                       
                       
<a style="margin-left:100px;" class="btn btn-danger btn-sm" href=""><i class="fa fa-trash fa-fw" style="margin-right:2px;"></i> Delete</a>
                   </div>
                   <!-- end database operational buttons ---------------------------------------------------------------------------------------->
                   
                   <!-- content area -->
                   
                   
                   
                   <!-- part details -->
                   
                   <div class="row">
                       
                   <div class="col-lg-10">
                       <div class="panel panel-default" style="padding-bottom:15px;">
                       <div class="panel-heading">
                           Part Details
                       </div>
                       <!-- /.panel-heading -->
                       <div class="panel-body">
                           <!-- Nav tabs -->
                           <ul class="nav nav-pills">
                               <li class="active">
                                   <a href="#home-pills" data-toggle="tab">Details</a>
                               </li>
                               <li>
                                   <a href="#record-info-pills" data-toggle="tab">Record Info</a>
                               </li>
                               <li>
                                   <a href="#run-info-pills" data-toggle="tab">Run Info</a>
                               </li>
                               <li>
                                   <a href="#lot-info-pills" data-toggle="tab">Lot Info</a>
                               </li>
                           </ul>
                           <!-- Tab panes -->
                           <div class="tab-content">
                               <div class="tab-pane fade in active" id="home-pills">
                                   <div class="col-lg-6">
                                   <h3>Part Details</h3>
                                   <br />
                                   
                                   <table class="tabledetail">
                                       <tr>
                                           <td><b>Chip Number</b></td>
                                           <td><input type="text" name="chipNumber" value="<?php echo $p->chipNumber; ?>" /></td>
                                       </tr>
                                       <tr>
                                           <td><b>Substrate Number</b></td>
                                           <td><input type="text" name="subNumber" value="<?php echo $p->subNumber; ?>" /></td>
                                       </tr>
                                       <tr>
                                           <td><b>Aperture</b></td>
                                           <td><input type="text" name="aperture" value="<?php echo $p->aperture; ?>" /></td>
                                       </tr>
                                       <tr>
                                           <td><b>Functional Elements</b></td>
                                           <td><input type="text" name="elementsWorking" value="<?php echo $p->elementsWorking; ?>" /></td>
                                       </tr>
                                       <tr>
                                           <td><b>Elements in Design</b></td>
                                           <td><input type="text" name="elementsNumber" value="<?php echo $p->elementsNumber; ?>" /></td>
                                       </tr>
                                       <tr>
                                           <td><b>Data Rate</b></td>
                                           <td><input type="text" name="dataRate" value="<?php echo $p->dataRate; ?>" /></td>
                                       </tr>
                                       <tr>
                                           <td><b>Box Location</b></td>
                                           <td><input type="text" name="boxLocation" value="<?php echo $p->boxLocation; ?>" /></td>
                                       </tr>
                                       <tr>
                                           <td><b>Geographic Location</b></td>
                                           <td><input type="text" name="geographicLocation" value="<?php echo $p->geographicLocation; ?>" /></td>
                                       </tr>
                                       <tr>
                                           <td><b>Package Type</b></td>
                                           <td><input type="text" name="packageType" value="<?php echo $p->packageType; ?>" /></td>
                                       </tr>
                                       <input type="hidden" name="partID" value="<?php echo $p->partID; ?>" />
                                       <input type="hidden" name="runID_FK" value="<?php echo $p->runID_FK; ?>" />
                                       <input type="hidden" name="lotID_FK" value="<?php echo $p->lotID_FK; ?>" />
                                   </table>
                                   <br />
                                   <table class="tabledetail">
                                       <tr>
                                           <td><b>Part Notes</b></td>
                                       </tr>
                                       <tr>
                                           <td>
                                               <textarea name="partNotes" rows="3" cols="80"><?php if ($p->partNotes) { echo $p->partNotes; } ?></textarea>
                                           </td>
                                       </tr>
                                       <tr>
                                           <td><b>Misc Notes</b></td>
                                       </tr>
                                       <tr>
                                           <td>
                                               <textarea name="miscNotes" rows="3" cols="80"><?php if ($p->miscNotes) { echo $p->miscNotes; } ?></textarea>
                                           </td>
                                       </tr>
                                       <tr>
                                           <td><b>Instructions</b></td>
                                       </tr>
                                       <tr>
                                           <td>
                                               <textarea name="instructions" rows="3" cols="80"><?php if ($p->instructions) { echo $p->instructions; } ?></textarea>
                                           </td>
                                       </tr>
                                   </table>
                                   </div>
                                   
                                   <?php echo form_close(); ?>


Here is my controller...

Code:
public function update_part() {
        
        $data = array (
            'chipNumber' => $this->input->post('chipNumber'),
            'subNumber' => $this->input->post('subNumber'),
            'aperture' => $this->input->post('aperture'),
            'elementsWorking' => $this->input->post('elementsWorking'),
            'elementsNumber' => $this->input->post('elementsNumber'),
            'dataRate' => $this->input->post('dataRate'),
            //'lotCreatedOn' => time(),
            //'lotCreatedBy' => get user from active dir),
            'boxLocation' => $this->input->post('boxLocation'),
            'cabinetLocation' => $this->input->post('cabinetLocation'),
            'geographicLocation' => $this->input->post('geographicLocation'),
            'dateShipped' => $this->input->post('dateShipped'),
            'packageType' => $this->input->post('packageType'),
            'packageIDNum' => $this->input->post('packageIDNum'),
            'investigatePart' => $this->input->post('investigatePart'),
            'partNotes' => $this->input->post('partNotes'),
            'miscNotes' => $this->input->post('miscNotes'),
            'instructions' => $this->input->post('instructions'),
            'partUpdatedOn' => date("d/m/Y")
        );
        
        $this->load->model('model_data');
        $this->model_data->update_part_data($data);
        $this->load->view('part_attachment', $data);
        
    }


and here is my model...

Code:
public function update_part_data($data){
        $this->db->where('partID', $this->uri->segment(5));
        $this->db->update('dev_db_parts', $data);
        
   }

partUpdatedOn is the only field that gets updated corectly in the database
thank you for your help
Reply
#2

There could be a number of reasons for this to happen.

In your view, you close a div after opening your form, but the div wasn't opened inside the form. The browser could decide that your form should be closed at this point, which would mean that all of the fields in your form are not included when you submit. Since 'partUpdatedOn' is one of the only fields which is not set by $this->input->post(), I wouldn't be surprised if this was the case (or if you're using some JavaScript to submit your page and not submitting the data properly).

You're also passing three parameters to the controller's method according to the form_open() call, but you aren't processing those parameters in your controller. Instead of calling $this->uri->segment(5) in your model, you should retrieve this field in the controller and pass it to your model (either as another argument or within $data). Pulling this data in at the controller also gives you a chance to make sure you have the ID before you move along to updating the data.

Some of the fields you're setting in the controller ('cabinetLocation', 'dateShipped', 'packageIDNum', and 'investigatePart') are not included on the form, so you should probably check whether those fields exist before setting their values in $data.

Are you using the update_part() method only to perform updates, or is it being used to load the form initially, too?
Reply
#3

Thanks for all the great advice, I will look into this and let you know what I find out
Reply




Theme © iAndrew 2016 - Forum software by © MyBB