[eluser]deongee[/eluser]
I have a edit form that updates all fields accept 1. The account_id field, which is not the primary id field will not update. Iām testing the ā account_idā input field. Here is my code.
Controller: manage.php
Code: function edit($account_id='', $platform =''){
if($account_id > ''){
$query = $this->db->get_where('db_accounts', array('account_id' => $account_id));
if(isset($query))
if ($query->num_rows() > '')
{
$row = $query->row_array();
}
$data['account_id'] = '';
$data['platform'] = '';
$data['name'] = '';
$data['location_city'] = '';
$data['location_country'] = '';
$data['status'] = '';
$data['region'] = '';
$data['link'] = '';
$data['type'] = '';
$data['faccount_id']['value'] = $row['account_id'];
$data['fplatform']['value'] = $row['platform'];
$data['fname']['value'] = $row['name'];
$data['flocation_city']['value']= $row['location_city'];
$data['flocation_country']['value'] = $row['location_country'];
$data['fstatus']['value'] = $row['status'];
$data['fregion']['value'] = $row['region'];
$data['flink']['value'] = $row['link'];
$data['ftype']['value'] = $row['type'];
}
if(isset($account_id)){
$this->form_validation->set_rules('account_id', 'Account ID', 'trim|required');
$this->form_validation->set_rules('platform', 'Platform', 'trim|required');
$this->form_validation->set_rules('name', 'Name', 'trim|required');
$this->form_validation->set_rules('status', 'Status', 'trim|required');
$this->form_validation->set_rules('location_city', 'City', 'required');
$this->form_validation->set_rules('location_country', 'Country', 'required');
$this->form_validation->set_rules('region', 'Region', 'required');
$this->form_validation->set_rules('link', 'Link', 'trim|required');
$this->form_validation->set_rules('type', 'Type', 'trim|required');
if($this->form_validation->run()){
if($query = $this->dashboard_model->update_account()){ //If successful update
$data['message'] = ' - Update complete!';
}else{
$data['message'] = 'There was an error, update not complete.';
}}
$data['account'] = $this->dashboard_model->get_account($account_id,$platform);
$this->load->view('manage/edit',$data);
}
}
Model: dashboard_model.php
Code: function update_account(){
$data = array(
'account_id'=>$this->input->post('account_id'),
'name'=>$this->input->post('name'),
'status' => $this->input->post('status'),
'location_city' => $this->input->post('location_city'),
'location_country' => $this->input->post('location_country'),
'region' => $this->input->post('region'),
'link' => $this->input->post('link'),
'type' => $this->input->post('type'));
$where = array(
'account_id' => $this->input->post('account_id'),
'platform' => $this->input->post('platform'));
$update = $this->db->update('db_accounts', $data, $where);
return $update;}
}?>
View: edit.php
Code: <?php
$hidden = array(
'account_id' => $faccount_id['value'],
'platform' => $fplatform['value'],
'name' => $fname['value'],
'status' => $fstatus['value'],
'location_city' => $flocation_city['value'],
'location_country' => $flocation_country['value'],
'region' => $fregion['value'],
'link' => $flink['value'],
'type' => $ftype['value']);
echo '<form method="post" accept-charset="utf-8">';
echo form_hidden($hidden);
echo '<span font-weight:bold"><font color="#C40909">'.$fplatform['value'].'</font>' ;
if(isset($message))
{echo '<font color=#C40909> '.$message.'</font></span>';};
echo '<h1 class="header"><span class="title">' .set_value('name', $fname['value']).'</span></h1>'; ?>
<table width="840" cellpadding="0" cellspacing="0" cols="3" color:#000; font-weight:bold; margin-top:10px;">
<tr><td><?php echo form_label('Name', 'name');
echo '<span color:#C40909;">'.form_error('name',' *');
echo form_input('name', set_value('name', $fname['value']),'style="width: 388px;"'); '</span>'?></td>
<td><?php echo form_label('Status', 'status');
$status_options = $this->lang->line('status');
echo form_dropdown('status', $status_options, set_value('status', $fstatus['value']), 'style="width: 200px; height:30px;"');?></td>
<td><?php echo form_label('Type', 'type');
$type_options = $this->lang->line('type');
echo form_dropdown('type', $type_options, set_value('type', $ftype['value']), 'style="width: 200px; height:30px;"');?></td>
</tr>
<tr><td><?php echo form_label('City', 'location_city');echo '<span color:#C40909;">'.form_error('location_city',' *'); echo form_input('location_city', set_value('location_city', $flocation_city['value']),' 388px;"'); '</span>' ?></td>
<td colspan="2"><?php echo form_label('Region', 'region');
$region_options = $this->lang->line('region');
echo form_dropdown('region', $region_options, set_value('region', $fregion['value']), 'style="width: 410px; height:30px;"');?>
<span color:#C40909;"><?php echo form_error('region',' '); ?></span></td></tr>
<tr><td height="20px;">Country <span color:#C40909;"><?php echo form_error('location_country',' *');?></span>
<?php echo form_input('location_country', set_value('location_country', $flocation_country['value']),'style="width: 388px;"'); ?></td>
<td colspan="2"><?php echo form_label('Link', 'link');
echo '<span color:#C40909;">'.form_error('link',' *'); echo form_input('link', set_value('link', $flink['value']),' 388px;"'); '</span>' ?></td></tr>
<tr><td colspan="2"><?php echo form_label('Account ID', 'account_id');
echo '<span color:#C40909;">'.form_error('account_id',' *');
echo form_input('account_id', set_value('account_id', $faccount_id['value']),'style="width: 388px;"'); '</span>'?></td></tr>
<tr><td colspan="3"><?php $data = array('name' => 'submit', 'value' => 'Update Account');echo form_submit($data); echo form_close();?></td></tr></table></div></div>
|