Irene Baluis Irene Baluis - 4 months ago 18
PHP Question

Data does not save and not displaying any error - Codeigniter

The data doesn't save without prompting any errors in my code

Here is my code in my Controller

function saveDebit(){
$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
$this->form_validation->set_rules('accountName', 'Account Name', 'required');
$this->form_validation->set_rules('amountDebit', 'Amount', 'required|numeric');

if ($this->form_validation->run() == FALSE) {
} else {
$debitData = array(
'Series' => $jevseries,
'AccountCode' => $this->input->post('accountName'),
'Account' => $account,
'Amount' => $this->input->post('amountDebit'),
'Count' => $count);




function entryDebit($debitData){
$this->db->insert('generalaccount', $debitData);

This is my View

<?php echo form_open('Jev/saveDebit'); ?>
<table class="jev_entry" id="jev_entry">
<?php echo form_hidden('series', $series);?>
$account_array = array();
foreach($accountNames as $account ){
$account_array []= $account->accountName;

echo form_dropdown('accountName', $account_array,'', 'class="form-control"');

<td><?php echo form_input('amountDebit','', 'class="form-control"');?><div class="error"><?php echo form_error('amountDebit'); ?></div></td>
<td align="center"><?php echo '<center>'. form_submit('submit','Save').'</center>'; ?> </td>

I don't know where is the error in this lines.. Your help is very much appreciated.


Okay i have found out what is wrong, The form_input of codeigniter only gives the form with a label. It does not give a name therefore we cannot post it since it doesn't have a name. Do this :)

$data = array(
        'name'          => 'username',
        'id'            => 'username',
        'value'         => 'johndoe',
        'maxlength'     => '100',
        'size'          => '50',
        'style'         => 'width:50%'

echo form_input($data);

It's like that and we post the name. Of course you can remove some parameters. More info in the form helper user guide in codeigniter :)

Godluck meyt