我在更新或编辑一对多关系中的特定数据时遇到问题。这是图片 - >
在我的数据库中,我有一个“Idcertificate”,它是主键,我也“Id”是一个外键。这是我的照片 - >
这是我的观点:
<div class="modal fade" id="myModals" role="dialog">
<div style="margin-top: 100px;" class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title text-center">Certificates and Awards</h4>
</div>
<div class="modal-body">
<?php
if ( isset($message) ){
echo $message;
} else{
foreach ($r as $index => $r)
{
?>
<form method="POST" action="<?php echo site_url("certificates/editon/".$r->Id) ?>">
<input class="input-lg " type="hidden" name="Id" placeholder="<?php echo $r->Id ?>" readonly="">
<input class="input-lg " type="hidden" name="Idcertificate" placeholder="<?php echo $r->Idcertificate ?>" readonly="">
<input class="input-lg text-capitalize" type="text" name="AwardsReceived" placeholder="Certificates/Awards Received" value="<?php echo $r->Certificates ?>" >
<input class="input-lg text-capitalize" type="text" name="Year" placeholder="Year" value="<?php echo $r->Year?>">
<input class="input-lg text-capitalize" type="text" name="Place" placeholder="Place" value="<?php echo $r->Place ?>">
<?php } } ?>
<br><br> <div class="modal-footer">
<button type="submit" class="btn btn-default" >Update</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
</form>
</div>
</div>
</div>
</div>
这是我的控制者:
function editon($Id){
$data= Array(
'Idcertificate' => $this->input->post('Idcertificate'),
'Certificates' => $this->input->post('AwardsReceived'),
'Year' => $this->input->post('Year'),
'Place' => $this->input->post('Place'),
);
$this->db->where('Id', $Id);
$this->db->update('certificatesawardsreceived',$data);
redirect('viewstudentinalpha/index');
}
}
答案 0 :(得分:1)
尝试使用(int)
$data= array(
'Idcertificate' => $this->input->post('Idcertificate'),
'Certificates' => (int)$this->input->post('AwardsReceived'),
'Year' => $this->input->post('Year'),
'Place' => $this->input->post('Place'),
);
$this->db->where('Id', $Id);
$this->db->update('certificatesawardsreceived',$data);