I want to update the 'not yet' status to 'already'
Have error
A Database Error Occurred
Error Number: 1054
Unknown column 'sudah' in 'field list'
UPDATE `tb_peserta` SET `sudah` = '' WHERE `no_pendaftaran` = '13'
Filename: C:/xampp/htdocs/codeigniter/system/database/DB_driver.php
Line Number: 691
My Controller
function status_verifikasi($no_pendaftaran){
$where = array('no_pendaftaran' => $no_pendaftaran);
$this->M_pendaftar->status_verifikasi($where,'tb_peserta');
redirect('admin/Ca_pendaftar');}
My Model
function status_verifikasi($where,$tb_peserta){
if ($status_verifikasi ='belum') {
$this->db->set('sudah');
} else{
$this->db->set('belum');
}
$this->db->where($where);
$this->db->update($tb_peserta);}
My View
<?=anchor('admin/Ca_pendaftar/status_verifikasi/'.$tb_peserta->no_pendaftaran,
'Konfirmasi', ['class'=>'btn btn-success btn-sm' , 'onclick'=>"return confirm('Ubah status pendaftar ?');"])?>
Codeigniter Set
syntax should be
$this->db->set('column_name','value');
Note : Equal =
is assignment operator . To compare you need to use ==
comparison operator
if ($status_verifikasi == 'belum') { .. }
Update1:
you need to check the previous value using select query like this then you need to update the status based on previous value .
function status_verifikasi($where,$tb_peserta){
$this->db->select('status_verifikasi');
$this->db->from($tb_peserta);
$this->db->where($where);
$result = $this->db->get()->result();
if($result && $result[0]->status_verifikasi =='belum')
{
$this->db->set('status_verifikasi','sudah');
} else{
$this->db->set('status_verifikasi','belum');
}
$this->db->where($where);
$this->db->update($tb_peserta);
}
$this->db->set('sudah');
should be something like
$this->db->set('sudah', 'value');
There is one more issue
// you have used assignment operator instead of comparison operator
if ($status_verifikasi ='belum') {
should be
if ($status_verifikasi == 'belum') {
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.