⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Cannot update table columns



darreno

darreno
  • profile picture
  • Member

Posted 17 April 2017 - 01:27 AM

Hi,

 

I have been using the example crud database without any problems and can edit any columns. etc.

 

I imported some tables (using sql) into the same example crud database and can list them, view, etc.

 

I can edit some columns and some not, anyone know what could be the problem?

 

Some column fields are empty and when I try to edit the list and the database do not get updated.

 

Below are 2 fields in my table, Phone and Techid.

 

The Phone field I can edit and update without any problems.

 

The Techid field does not get updated even though the edit.php indicates the edit was successful.

 

Any help would be appreciated.

 

</div>   <div class='form-field-box odd' id="Phone_field_box">   <div class='form-display-as-box' id="Phone_display_as_box">   Phone :   </div>   <div class='form-input-box' id="Phone_input_box">   <input id='field-Phone' class='form-control' name='Phone' type='text' value="6164574604" maxlength='27' /> </div>   <div class='clear'></div>   </div>   <div class='form-field-box even' id="TechId_field_box">   <div class='form-display-as-box' id="TechId_display_as_box">   TechId :   </div>   <div class='form-input-box' id="TechId_input_box">   <input id='field-TechId' class='form-control' name='TechId' type='text' value="n/a" maxlength='15' /> </div>   <div class='clear'></div>   </div>


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 17 April 2017 - 06:56 AM

Hi,

 

Can you paste in the Table structure, the code that u used. Once shared, we can actually look in as where the actual issue may arise..


darreno

darreno
  • profile picture
  • Member

Posted 17 April 2017 - 12:09 PM

Hi Amit,

 

Here is the table that I inserted into the example database:

 

CREATE TABLE `tor` (
  `SerialNumber` varchar(4) NOT NULL DEFAULT '',
  `Manager` varchar(24) DEFAULT NULL,
  `Technician Name` varchar(30) DEFAULT NULL,
  `Email` varchar(40) DEFAULT NULL,
  `Phone` varchar(27) DEFAULT NULL,
  `TechId` varchar(15) DEFAULT NULL,
  `dateissued` varchar(11) DEFAULT NULL,
  `dateaudited` varchar(12) DEFAULT NULL,
  `datereturned` varchar(13) DEFAULT NULL,
  PRIMARY KEY (`SerialNumber`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
INSERT INTO `tor` (`SerialNumber`, `Manager`, `Technician Name`, `Email`, `Phone`, `TechId`, `dateissued`, `dateaudited`, `datereturned`) VALUES
('Y001', 'david smith', '', 'david.smith@email.com', '4247283035', '2693', '', '', ''),
('Y002', 'john smith', 'john smith', 'john.smith@email.com', '6142777114', '2718', '', '', ''),
('Y003', 'jane smith', 'jane smith', 'jane.smith@email.com', '1234567890', 'n/a', '', '', '');
 
I can edit this table contents from phpmyadmin no problems.
 
I cannot update it from grocery_crud but I can update the other tables.
 
Thanks!

 


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 17 April 2017 - 12:34 PM

Fine with the structure.. can u share the code too... .thats where i can look in where and why if there is an issue for updation!!!


darreno

darreno
  • profile picture
  • Member

Posted 17 April 2017 - 18:38 PM

Hi Amit,

 

The Examples.php controller:

 

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
class Examples extends CI_Controller {
 
public function __construct()
{
parent::__construct();
 
$this->load->database();
$this->load->helper('url');
$this->load->library('grocery_CRUD');
}
 
public function _example_output($output = null)
{
$this->load->view('example.php',(array)$output);
}
 
public function offices()
{
$output = $this->grocery_crud->render();
 
$this->_example_output($output);
}
 
public function index()
{
$this->_example_output((object)array('output' => '' , 'js_files' => array() , 'css_files' => array()));
}

 

    function tor()
    {
    $crud = new grocery_CRUD();
    $crud =>set_theme('datatables');
    $crud->set_table('tor');
    $crud->columns('SerialNumber','Manager','Technician Name', 'Email', 'Phone', 'Tech Id', 'Date Issued', 'Date Audited', 'Date Returned');
    $crud->field_type('SerialNumber', 'readonly');
    $output = $crud->render();
 
    $this->_example_output($output);
    }
}
    

The view example.php

 

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
<?php 
foreach($css_files as $file): ?>
<link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />
<?php endforeach; ?>
<?php foreach($js_files as $file): ?>
<script src="<?php echo $file; ?>"></script>
<?php endforeach; ?>
</head>
<body>
<div>
<a href='<?php echo site_url('examples/tor')?>'>>TOR</a>
 
</div>
<div style='height:20px;'></div>  
    <div>
<?php echo $output; ?>
    </div>
</body>
</html>
 
The edit view from datatables theme folder:
 
<div style='height:20px;'></div>   <div>   <div class='ui-widget-content ui-corner-all datatables'>   <h3 class="ui-accordion-header ui-helper-reset ui-state-default form-title">   <div class='floatL form-title-left'>   <a href="#">Edit Record</a>   </div>   <div class='clear'></div>   </h3>   <div class='form-content form-div'>   <form action="http://localhost/examples/tor/update/1" method="post" id="crudForm" enctype="multipart/form-data" accept-charset="utf-8">   <div>   <div class='form-field-box odd' id="SerialNumber_field_box">   <div class='form-display-as-box' id="SerialNumber_display_as_box">   SerialNumber :   </div>   <div class='form-input-box' id="SerialNumber_input_box">   <div id="field-SerialNumber" class="readonly_label">Y001</div> </div>   <div class='clear'></div>   </div>   <div class='form-field-box even' id="Manager_field_box">   <div class='form-display-as-box' id="Manager_display_as_box">   Manager :   </div>   <div class='form-input-box' id="Manager_input_box">   <input id='field-Manager' class='form-control' name='Manager' type='text' value="david smilth" maxlength='30' /> </div>   <div class='clear'></div>   </div>   <div class='form-field-box odd' id="Technician Name_field_box">   <div class='form-display-as-box' id="Technician Name_display_as_box">   Technician Name :   </div>   <div class='form-input-box' id="Technician Name_input_box">   <input id='field-Technician Name' class='form-control' name='Technician Name' type='text' value="david smith" maxlength='20' /> </div>   <div class='clear'></div>   </div>   <div class='form-field-box even' id="Email_field_box">   <div class='form-display-as-box' id="Email_display_as_box">   Email :   </div>   <div class='form-input-box' id="Email_input_box">   <input id='field-Email' class='form-control' name='Email' type='text' value="david.smith@email.com" maxlength='30' /> </div>   <div class='clear'></div>   </div>   <div class='form-field-box odd' id="Phone_field_box">   <div class='form-display-as-box' id="Phone_display_as_box">   Phone :   </div>   <div class='form-input-box' id="Phone_input_box">   <input id='field-Phone' class='form-control' name='Phone' type='text' value="4247283035" maxlength='11' /> </div>   <div class='clear'></div>   </div>   <div class='form-field-box even' id="Tech Id_field_box">   <div class='form-display-as-box' id="Tech Id_display_as_box">   Tech Id :   </div>   <div class='form-input-box' id="Tech Id_input_box">   <input id='field-Tech Id' class='form-control' name='Tech Id' type='text' value="2693" maxlength='6' /> </div>   <div class='clear'></div>   </div>   <div class='form-field-box odd' id="Date Issued_field_box">   <div class='form-display-as-box' id="Date Issued_display_as_box">   Date Issued :   </div>   <div class='form-input-box' id="Date Issued_input_box">   <input id='field-Date Issued' name='Date Issued' type='text' value='' maxlength='10' class='datepicker-input form-control' />   <a class='datepicker-input-clear' tabindex='-1'>Clear</a> (dd/mm/yyyy) </div>   <div class='clear'></div>   </div>   <div class='form-field-box even' id="Date Audited_field_box">   <div class='form-display-as-box' id="Date Audited_display_as_box">   Date Audited :   </div>   <div class='form-input-box' id="Date Audited_input_box">   <input id='field-Date Audited' name='Date Audited' type='text' value='' maxlength='10' class='datepicker-input form-control' />   <a class='datepicker-input-clear' tabindex='-1'>Clear</a> (dd/mm/yyyy) </div>   <div class='clear'></div>   </div>   <div class='form-field-box odd' id="Date Returned_field_box">   <div class='form-display-as-box' id="Date Returned_display_as_box">   Date Returned :   </div>   <div class='form-input-box' id="Date Returned_input_box">   <input id='field-Date Returned' name='Date Returned' type='text' value='' maxlength='10' class='datepicker-input form-control' />   <a class='datepicker-input-clear' tabindex='-1'>Clear</a> (dd/mm/yyyy) </div>   <div class='clear'></div>   </div>   <!-- Start of hidden inputs -->   <!-- End of hidden inputs -->   <div class='line-1px'></div>   <div id='report-error' class='report-div error'></div>   <div id='report-success' class='report-div success'></div>   </div>   <div class='buttons-box'>   <div class='form-button-box'>   <input id="form-button-save" type='submit' value='Update changes' class='ui-input-button' />   </div>   <div class='form-button-box'>   <input type='button' value='Update and go back to list' class='ui-input-button' id="save-and-go-back-button"/>   </div>   <div class='form-button-box'>   <input type='button' value='Cancel' class='ui-input-button' id="cancel-button" />   </div>   <div class='form-button-box loading-box'>   <div class='small-loading' id='FormLoading'>Loading, updating changes...</div>   </div>   <div class='clear'></div>   </div>   </form>   </div>   </div>   <script>   var validation_url = 'http://localhost/examples/region/tor/update_validation/2';   var list_url = 'http://localhost/examples/region/tor/';       var message_alert_edit_form = "The data you had change may not be saved.\nAre you sure you want to go back to list?";   var message_update_error = "An error has occurred on saving.";   </script><script type="text/javascript">   var js_date_format = 'dd/mm/yy';   </script>   <script type="text/javascript">   var default_javascript_path = 'http://localhost/examples/assets/grocery_crud/js';   var default_css_path = 'http://localhost/examples/assets/grocery_crud/css';   var default_texteditor_path = 'http://localhost/examples/assets/grocery_crud/texteditor';   var default_theme_path = 'http://localhost/examples/assets/grocery_crud/themes';   var base_url = 'http://localhost/examples/';       </script>   </div>   </body>   </html>

 


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 18 April 2017 - 10:30 AM

well sorry to say ... you seems to be trying to hide your piece of code..

i am not interested in the view part .. but the controller code...

what is it that is causing the field not being updated...

 

The code above dose not have the said functionality.. 

Looking at this, one may never be able to come to conclusion .. to what the problem is and how to resolve the same.


darreno

darreno
  • profile picture
  • Member

Posted 19 April 2017 - 00:15 AM

I do not understand what you mean by "trying to hide your piece of code".

 

The Example.php controller was part of the code when downloading Grocery Crud.

 

I removed the functions like employee_management(), office_management(), etc and inserted my own function tor() and created a table called tor in the example database.

 

function tor()
    {
    $crud = new grocery_CRUD();
    $crud =>set_theme('datatables');
    $crud->set_table('tor');
    $crud->columns('SerialNumber','Manager','Technician Name', 'Email', 'Phone', 'Tech Id', 'Date Issued', 'Date Audited', 'Date Returned');
    $crud->field_type('SerialNumber', 'readonly');
    $output = $crud->render();
 
    $this->_example_output($output);
 
Can you tell me if I am missing something or what you need to see.

Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 19 April 2017 - 09:16 AM

Ok .. let me make myself clear .. what you facing the problem u not able to see the TechId value on the grid.. 

The reason for the same what i see is .. the field in the table is TechId and the one in the column is 'Tech Id'

If you see in the db backend .. using phpmyadmin or any mysql db admin interface for the table - u will find the value being set there .. and the same wont be in display in the grid cuz of the difference in the name of the field. .. in the columns it should be 'TechId' and not 'Tech Id'. 

As for the naming conventions. . just on the personal grounds, it would be better if u can maintain the fields without spaces ' ' . For the purpose of display - u can use display_as .... function. 

 

Hope this solves your issue..

 

Happy GCing :)


darreno

darreno
  • profile picture
  • Member

Posted 19 April 2017 - 13:12 PM

Thanks Amit!

 

I see what you mean, I understand, thank you for help!