0

I am making an application in codeigniter using php.I want to insert data into database table where the data is entered in an input box inside a loop.I have tried the below code so far:

cms_model.php

public function loadadd($mekhala_Id){
    
        $query = $this->db->get_where('tb_unit', array('mandalam_Id' => $mekhala_Id));
        echo  form_open('Payment/amount'); 
    ?>


<h1>Members List</h1>
        <table border="1">
            <tr>
                 <th>Unit</th>
                  <th>Unit Secretary</th>
                 <th>Amount paid</th>
                 
            </tr>
            <?php
    foreach ($query->result() as $row)
    {
        ?>

            <tr>
                <td> <?php echo $row->unitName ;?></td>
                        <td> <?php echo $row->unit_sec ;?></td>
                       <td> <?php echo form_input(array('name'=>'na','placeholder'=>'Rupees Paid')) ;?></td>  
            </tr>
            <?php
       
}

 echo form_submit(array('name'=>'sub','value'=>'submit'));
        echo form_close();
}



 public function loadpayment($paid){
 
   //  $paid= $this->input->post('na');

           $fieldsData = $this->db->field_data('tb_unit');
           $datacc = array(); // you were setting this to a string to start with, which is bad

     foreach ($fieldsData as $key => $field)
{
    $datacc[ $field->Amount] = $this->input->post( $field->Amount);
}
$this->db->insert('tb_unit', $datacc);

}
   //  $this->db->set('Amount', $paid)



  
}



        
?> 
   

I have encountered below error while running this code:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: stdClass::$Amount

Filename: models/cms_model.php

Line Number: 110

Please help me to resolve this error.

1
  • Any one please help me to find answer. Commented May 21, 2016 at 7:56

1 Answer 1

0

change line #110 to:

$datacc[$field->name] = $this->input->post($field->name);
Sign up to request clarification or add additional context in comments.

16 Comments

Still data is not being inserted into the database table
can you tell the error after changing your editing your code?
No error..But data is not being inserted into the database table.
can you tell me what you are trying to achieve??
Actually i want to store the data that is inserted into the the input box which is provided inside a loop..While running the above code no error is being shown where as the inserted data is not stored in the database table.How can i resolve this problem???
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.