Click here to Skip to main content
15,037,420 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
My apology, I added new fields in table and didn't added field names in allowedFields variable of Model, which was causing not to update the table.

Hello,

I wanted to Update Record in Database but its not updating record without showing any error.

The message Fee Receipt Updated Successfully is showing up but record is not updating.

Fee receipt updated successfully popsup but record not updating


Don't know what is wrong in my code.

Below is my View editreceipt:

PHP
<table class="table table-bordered table-striped table-hover">
    <form method="POST" action="<?php echo base_url(); ?>/FeeReceipts/updatereceipt" >
    <?php foreach($results as $row){ ?>
    <tr>
    <th>Institution: </th> <td><?php echo $row->institutionname; ?>
    <input type="hidden" name = "id" value="<?php echo $row->receiptno; ?>" /> </td>
    <th>Session: </th> <td><?php echo $row->sessionname; ?></td>
    </tr>
    <th>Class: </th> <td><?php echo $row->classname; ?></td>
    <th>Section: </th> <td><?php echo $row->sectionname; ?></td>
    </tr>
    <tr>
    <th>Admission No: </th> <td><?php echo $row->admissionno; ?></td>
    <th>Name: </th> <td><?php echo $row->studentname; ?></td>
    </tr>
    <tr>
    <th>Class Fee: </th> <td><?php echo $row->classfee; ?></td>
    <th>Discount: </th> <td><?php echo $row->totaldiscount; ?></td>
    </tr>

    <tr>
    <?php $payable = $row->classfee - $row->totaldiscount; ?>
    <th>Payable: </th> <td><?php echo $payable; ?></td>
    <?php 
    $p = "";
    if($row->paid==0){
      $p = '<input type="checkbox" checked="false" class="form-control" onclick="return false;" />';
    }
      else
      {
        $p = '<input type="checkbox" checked="true" class="form-control" onclick="return false;" />';
      }
      ?>
    <th>Paid: </th> <td><?php echo $p; ?></td>
    </tr>
    <tr>
    <th>Addition Fee: </th> <td><input type="text" name = "additionalfee" value="<?php echo $row->additionalfee; ?>" /> </td>
    <th>Instant Discount: </th> <td><input type="text" name = "instantdisc" value="<?php echo $row->instantdisc; ?>" /></td>
    </tr>
    <tr>
    <th>Remarks: </th> <td><input type="text" name = "remarks" value="<?php echo $row->remarks; ?>" /> </td>
    <th>Paid Amount: </th> <td><input type="text" name = "paidamount" value="<?php echo $row->paidamount; ?>" /></td>
    </tr>
<?php } ?>
<button type="submit" class="btn btn-success">Update Receipt</button>
</form>
    </table>


What I have tried:

PHP
  public function updatereceipt()
  {
   $model = new FeeReceiptModel();
   $id = $this->request->getVar('id');
   $data = ['additionalfee' => $this->request->getVar('additionalfee'),
   'instantdisc' => $this->request->getVar('instantdisc'),
   'remarks' => $this->request->getVar('remarks'),
   'paidamount' => $this->request->getVar('paidamount')];
  if($model->update($id,$data)){
echo "<script>alert('Fee receipt updated successfully!');window.location.href='".base_url()."/feereceipts';</script>";
  }
  }
Posted
Updated 7-Feb-21 19:31pm
v4
Comments
[no name] 6-Feb-21 12:51pm
   
Most probably you should give a hint how $model->update($id,$data)){ is implementd?
nyt1972 6-Feb-21 13:00pm
   
Sorry I didn't understand your question but if($model->update($id,$data)){ returning successful message

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900