Welcome Guest, Not a member yet? Register   Sign In
form field not updating
#1

[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>'; ?&gt;
<table width="840" cellpadding="0" cellspacing="0" cols="3"  color:#000; font-weight:bold; margin-top:10px;">
<tr><td>&lt;?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>'?&gt;</td>
<td>&lt;?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;"');?&gt;</td>
<td>&lt;?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;"');?&gt;</td>
</tr>
<tr><td>&lt;?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>' ?&gt;</td>
<td colspan="2">&lt;?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;"');?&gt;
<span  color:#C40909;">&lt;?php echo form_error('region',' '); ?&gt;</span></td></tr>
<tr><td  height="20px;">Country <span  color:#C40909;">&lt;?php echo form_error('location_country',' *');?&gt;</span>
&lt;?php echo form_input('location_country', set_value('location_country', $flocation_country['value']),'style="width: 388px;"'); ?&gt;</td>
<td colspan="2">&lt;?php echo form_label('Link', 'link');
echo '<span  color:#C40909;">'.form_error('link',' *'); echo form_input('link', set_value('link', $flink['value']),' 388px;"'); '</span>' ?&gt;</td></tr>
<tr><td colspan="2">&lt;?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>'?&gt;</td></tr>
<tr><td colspan="3">&lt;?php $data = array('name' => 'submit', 'value' => 'Update Account');echo form_submit($data); echo form_close();?&gt;</td></tr></table></div></div>


Messages In This Thread
form field not updating - by El Forum - 03-29-2013, 09:06 AM
form field not updating - by El Forum - 03-29-2013, 09:43 AM
form field not updating - by El Forum - 03-29-2013, 09:53 AM
form field not updating - by El Forum - 03-29-2013, 10:11 AM
form field not updating - by El Forum - 03-29-2013, 10:25 AM
form field not updating - by El Forum - 03-29-2013, 10:54 AM
form field not updating - by El Forum - 03-29-2013, 10:59 AM
form field not updating - by El Forum - 03-29-2013, 11:12 AM
form field not updating - by El Forum - 03-29-2013, 11:25 AM
form field not updating - by El Forum - 03-29-2013, 12:12 PM
form field not updating - by El Forum - 04-01-2013, 05:52 AM



Theme © iAndrew 2016 - Forum software by © MyBB